-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanual.py
41 lines (36 loc) · 1.66 KB
/
manual.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import requests
import pytz
from datetime import datetime
import os
def capitalizy(input_string):
return input_string.title()
def convert_tz(time_str):
try:
input_datetime = datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S")
except ValueError:
input_datetime = datetime.strptime(time_str, "%A, %B %d, %Y at %I:%M %p")
source_timezone = pytz.utc
timezone = "US/Central"
target_timezone = pytz.timezone(timezone)
localized_datetime = source_timezone.localize(input_datetime)
converted_datetime = localized_datetime.astimezone(target_timezone)
date = converted_datetime.strftime("%B %dth, %A %Y at %I:%M %p")
return date
days = os.environ['days']
channel_id = os.environ['channel_id']
api_key = os.environ['api_key']
with requests.get(f'https://channel-update-api.vercel.app/check?channel_id={channel_id}&api_key={api_key}&days_ago={days}') as app:
aps = app.json()
if aps['text'].startswith("No videos uploaded"):
print("No video uploaded D:")
elif aps['text'].startswith("Videos"):
for video in aps['videos']:
title = capitalizy(video['channel_title'])
#formatted_datetime = convert_tz(video['published'])
print(f"\033[92mYay! {title} released {capitalizy(video['title'])} on {video['published']}\nWatch it here: {video['url']}\033[0m")
elif app.status_code == 400:
print("Please provide a channel id and api key or valid channel ids and api keys :D")
exit(-1)
else:
print(f"Oh no! the api has encountered an error! Please create an issue in the issue tab. Status code: \n{app.status_code}\nError text: \n{app.text}")
exit(-1)