mirror of
https://github.com/JonasunderscoreJones/turbo-octo-potato.git
synced 2025-10-25 19:19:19 +02:00
Compare commits
No commits in common. "ccca4cb42b3b9ed0701f9ea124552dfd5d9715e1" and "2f421d81b895fa6d40f3adf38a83745bd5612662" have entirely different histories.
ccca4cb42b
...
2f421d81b8
3 changed files with 8 additions and 82 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -3,5 +3,4 @@
|
||||||
__pycache__
|
__pycache__
|
||||||
.working
|
.working
|
||||||
rkpop_data.json
|
rkpop_data.json
|
||||||
/turbo-octo-potato
|
/turbo-octo-potato
|
||||||
mcmod_metadata.json
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
import os
|
|
||||||
import requests
|
|
||||||
import json
|
|
||||||
import dotenv
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
def send_webhook():
|
|
||||||
# Load the webhook URL from the environment variables
|
|
||||||
dotenv.load_dotenv()
|
|
||||||
|
|
||||||
# Replace with your actual webhook URL
|
|
||||||
webhook_url = os.getenv('DISCORD_WEBHOOK_URL')
|
|
||||||
|
|
||||||
today = datetime.datetime.today().date()
|
|
||||||
|
|
||||||
# Get the date from 7 days ago
|
|
||||||
seven_days_ago = today - datetime.timedelta(days=7)
|
|
||||||
|
|
||||||
# request with the date and http://api.jonasjones.dev/v1/kcomebacks/filter/daterange?start=2023-12-1&end=2023-12-16&limit=50&offset=0
|
|
||||||
response = requests.get(f"http://api.jonasjones.dev/v1/kcomebacks/filter/daterange?start={seven_days_ago}&end={today}&limit=50&offset=0")
|
|
||||||
|
|
||||||
# Check if the request was successful
|
|
||||||
if response.status_code != 200:
|
|
||||||
print(f"Failed to fetch data. Status code: {response.status_code}")
|
|
||||||
exit()
|
|
||||||
|
|
||||||
# Parse the JSON response
|
|
||||||
data = response.json()
|
|
||||||
data = data['results']
|
|
||||||
|
|
||||||
# check if there are 50 or more comebacks
|
|
||||||
if len(data) >= 50:
|
|
||||||
# request with offset 50
|
|
||||||
response = requests.get(f"http://api.jonasjones.dev/v1/kcomebacks/filter/daterange?start={seven_days_ago}&end={today}&limit=50&offset=50")
|
|
||||||
# Check if the request was successful
|
|
||||||
if response.status_code != 200:
|
|
||||||
print(f"Failed to fetch data. Status code: {response.status_code}")
|
|
||||||
exit()
|
|
||||||
|
|
||||||
# Parse the JSON response
|
|
||||||
data2 = response.json()
|
|
||||||
|
|
||||||
# join the lists
|
|
||||||
data += data2['results']
|
|
||||||
|
|
||||||
# Create the message content
|
|
||||||
content = "# Here are the comebacks from this week:\n"
|
|
||||||
for i in data:
|
|
||||||
content += f"{i['date']} > {i['title']} - {i['artist']}: {i['links'] if i['links'] != [] else '*No Links*'}\n"
|
|
||||||
|
|
||||||
# Message content
|
|
||||||
message = {
|
|
||||||
"content": content,
|
|
||||||
}
|
|
||||||
|
|
||||||
# Make the POST request to the webhook URL
|
|
||||||
response = requests.post(webhook_url, data=json.dumps(message), headers={"Content-Type": "application/json"})
|
|
||||||
|
|
||||||
# Check if the request was successful
|
|
||||||
if response.status_code == 204:
|
|
||||||
print("Webhook sent successfully!")
|
|
||||||
else:
|
|
||||||
print(f"Failed to send webhook. Status code: {response.status_code}")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
send_webhook()
|
|
||||||
20
rpopfetch.py
20
rpopfetch.py
|
|
@ -6,7 +6,6 @@ import re
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import rpop_webhook
|
|
||||||
|
|
||||||
def fetch_main_reddit_wiki_page(subreddit_name, page_name):
|
def fetch_main_reddit_wiki_page(subreddit_name, page_name):
|
||||||
|
|
||||||
|
|
@ -87,10 +86,10 @@ def convert_monthly_content_to_json(content, year, month):
|
||||||
parts[3] = parts[3][1:]
|
parts[3] = parts[3][1:]
|
||||||
if (parts[3].startswith("[") and parts[3].endswith(")")):
|
if (parts[3].startswith("[") and parts[3].endswith(")")):
|
||||||
parts[3] = parts[3][1:parts[3].find("](")]
|
parts[3] = parts[3][1:parts[3].find("](")]
|
||||||
|
|
||||||
if (parts[3].startswith("*[") and parts[3].endswith(")*")):
|
if (parts[3].startswith("*[") and parts[3].endswith(")*")):
|
||||||
parts[3] = parts[3][2:parts[3].find("](")]
|
parts[3] = parts[3][2:parts[3].find("](")]
|
||||||
|
|
||||||
releasetype = []
|
releasetype = []
|
||||||
|
|
||||||
# parse the release type
|
# parse the release type
|
||||||
|
|
@ -173,19 +172,19 @@ def convert_monthly_content_to_json(content, year, month):
|
||||||
else:
|
else:
|
||||||
# if the song links are not provided, replace the string with an empty list
|
# if the song links are not provided, replace the string with an empty list
|
||||||
parts[6] = []
|
parts[6] = []
|
||||||
|
|
||||||
# add the reddit link to the list of links
|
# add the reddit link to the list of links
|
||||||
reddit = parts.pop(5)
|
reddit = parts.pop(5)
|
||||||
if reddit != "":
|
if reddit != "":
|
||||||
parts[5].append(reddit)
|
parts[5].append(reddit)
|
||||||
|
|
||||||
# remove the "th", "st", "nd", "rd" from the day
|
# remove the "th", "st", "nd", "rd" from the day
|
||||||
parts[0] = parts[0].replace('th', '').replace('st', '').replace('nd', '').replace('rd', '')
|
parts[0] = parts[0].replace('th', '').replace('st', '').replace('nd', '').replace('rd', '')
|
||||||
|
|
||||||
# make the links an empty list if it's null
|
# make the links an empty list if it's null
|
||||||
if parts[5] == [None]:
|
if parts[5] == [None]:
|
||||||
parts[5] = []
|
parts[5] = []
|
||||||
|
|
||||||
# create a json entry from the parsed data
|
# create a json entry from the parsed data
|
||||||
json_entry = {
|
json_entry = {
|
||||||
"date": f"{year}-{month}-{parts[0]}",
|
"date": f"{year}-{month}-{parts[0]}",
|
||||||
|
|
@ -196,7 +195,7 @@ def convert_monthly_content_to_json(content, year, month):
|
||||||
"links": parts[5]
|
"links": parts[5]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
json_data.append(json_entry)
|
json_data.append(json_entry)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -248,7 +247,6 @@ def fetch_monthly_page(wiki_link, subreddit_name):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
UPLOAD_TO_CDN = True if "--cdn" in sys.argv else False
|
UPLOAD_TO_CDN = True if "--cdn" in sys.argv else False
|
||||||
SEND_WEBHOOK = False if "--no-webhook" in sys.argv else False if "-nwh" in sys.argv else True
|
|
||||||
|
|
||||||
# reddit infos
|
# reddit infos
|
||||||
subreddit_name = "kpop"
|
subreddit_name = "kpop"
|
||||||
|
|
@ -316,7 +314,7 @@ if content:
|
||||||
# save json_data to file
|
# save json_data to file
|
||||||
with open(f"rkpop_data.json", "w") as f:
|
with open(f"rkpop_data.json", "w") as f:
|
||||||
f.write(json.dumps(json_data, indent=4))
|
f.write(json.dumps(json_data, indent=4))
|
||||||
|
|
||||||
print("Fetched", len(json_data) - 1, "entries.")
|
print("Fetched", len(json_data) - 1, "entries.")
|
||||||
|
|
||||||
cdn_upload_cmd = "rclone copy rkpop_data.json cdn:cdn/api/kcomebacks/"
|
cdn_upload_cmd = "rclone copy rkpop_data.json cdn:cdn/api/kcomebacks/"
|
||||||
|
|
@ -327,7 +325,3 @@ if content:
|
||||||
elif input("Upload to cdn? [Y/n]") in ["Y", "y", ""]:
|
elif input("Upload to cdn? [Y/n]") in ["Y", "y", ""]:
|
||||||
print("Uploading...")
|
print("Uploading...")
|
||||||
os.system(cdn_upload_cmd)
|
os.system(cdn_upload_cmd)
|
||||||
|
|
||||||
|
|
||||||
if SEND_WEBHOOK:
|
|
||||||
rpop_webhook.send_webhook()
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue