aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPinapelz <donaldshan1@outlook.com>2023-05-06 21:58:49 -0700
committerPinapelz <donaldshan1@outlook.com>2023-05-06 21:58:49 -0700
commit7b0157a79378847bd3aa4e10e30f0a929ca27c53 (patch)
tree3d6b7738ffa01b9196a907d6e74dbbbdfc5f4700
parent178cb85d040ec73b7e0564169fe4b7cb2d05085a (diff)
Fixed auto generate channel data files
-rw-r--r--config.py7
-rw-r--r--main.py22
-rw-r--r--webapi/holodex.py8
3 files changed, 26 insertions, 11 deletions
diff --git a/config.py b/config.py
index 2c7f2eb..3b2404c 100644
--- a/config.py
+++ b/config.py
@@ -44,6 +44,11 @@ ROOT_STORAGE_PATH = ""
# Organization names must match the names on Holodex (case sensitive)
HOLODEX_ORG = "Nijisanji,Hololive" # Can be a comma separated list of organizations
ORG_MEMBER_COUNT = 300
-UPDATE_LOCAL_RECORDS = True # If true, will update the local records of the channels.txt and exclude_channels.txt files
+UPDATE_LOCAL_RECORDS = True # If true, will update the local records of the channels.txt and exclude_channels.txt file
+
+# URL for pulling the channels.txt and exclude_channels.txt file from a URL (should be raw txt form)
+# Provide link to the directory/base url that contains the channels.txt and exclude_channels.txt files
+EXTERNAL_DATA_URL = "https://raw.githubusercontent.com/pinapelz/NijiTrack/pettan-track-data/data/" # You'll need to manually call this
+REFRESH_DAILY = False # If true, will refresh the data from the external data url every day
diff --git a/main.py b/main.py
index f39df87..702eb9f 100644
--- a/main.py
+++ b/main.py
@@ -34,6 +34,8 @@ def update_database(server: SQLHandler, data):
# Difference should only be calculated every 24 hours
# If the channel is new then calculate now, else then make sure 24 hours has passed since last reading
if refresh_diff_table or not server.check_row_exists(DAY_DIFF_TABLE_NAME, "channel_id", channel_id):
+ if REFRESH_DAILY:
+ generate_channel_files()
if not server.check_row_exists(DAY_DIFF_TABLE_NAME, "channel_id", channel_id):
server.insert_data(DAY_DIFF_TABLE_NAME,
diff_columns, f"'{channel_id}', {sub_count}")
@@ -142,19 +144,23 @@ def generate_channel_files():
if not UPDATE_LOCAL_RECORDS:
return
print("Running Channel Files Update")
- hldex = HolodexAPI(fs.get_api_key("holodex_api_key"), member_count = ORG_MEMBER_COUNT,
- organization = HOLODEX_ORG)
- hldex.get_data_all_channels()
+ active_channels = []
+ exclude_channels = []
if not os.path.exists("data"):
os.mkdir("data")
+ for org in HOLODEX_ORG.split(","):
+ hldex = HolodexAPI(fs.get_api_key("holodex_api_key"), member_count = ORG_MEMBER_COUNT,
+ organization = org)
+ hldex.get_data_all_channels()
+ active_channels += hldex.get_active_channels()
+ exclude_channels += hldex.get_exclude_channels()
with open("data/channels.txt", "w", encoding="utf-8") as file:
- file.write("\n".join(hldex.get_active_channels()))
- with open("data/exclude_channels.txt", "w", encoding="utf-8") as file:
- file.write("\n".join(hldex.get_exclude_channels()))
+ file.write("\n".join(active_channels))
+ with open("data/exclude_channel.txt", "w", encoding="utf-8") as file:
+ file.write("\n".join(exclude_channels))
print("Success! Channel Files Updated!")
-
-if __name__ == "__main__":
+if __name__ == "__main2__":
MODE = 0
if len(sys.argv) > 1:
MODE = int(sys.argv[1])
diff --git a/webapi/holodex.py b/webapi/holodex.py
index 89fcc14..6a5dc93 100644
--- a/webapi/holodex.py
+++ b/webapi/holodex.py
@@ -28,8 +28,12 @@ class HolodexAPI(WebAPI):
members -= 100
offset += 100
for channel in data:
+ print(channel['name'])
if channel['inactive'] is False:
- self._active_channels.append(channel['id'])
+ try:
+ self._active_channels.append(channel['id'] + "," + channel['english_name'])
+ except (KeyError, TypeError, ValueError):
+ self._active_channels.append(channel['id'] + "," + channel['name'])
channel['description'] = self.get_channel_description(channel['id'])
filtered_data.append(channel)
else:
@@ -60,4 +64,4 @@ class HolodexAPI(WebAPI):
"""
Gets the list of active channels
"""
- return self._active_channels
+ yield from self._active_channels
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage