forked from Mohammed-Faizzzz/Leetcode_Tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompletedLeetcode.py
68 lines (51 loc) · 2.25 KB
/
CompletedLeetcode.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import requests
import json
import telegram
import asyncio
from datetime import datetime, date, timedelta
from dotenv import load_dotenv
from pytz import timezone
import os
load_dotenv()
bot = telegram.Bot(token=os.getenv('TELEBOT_TOKEN'))
bbcgrpID_json = os.getenv('BBC_GRP_ID')
testgrpID_json = os.getenv('TEST_GRP_ID')
bbcgrpID = json.loads(bbcgrpID_json)
testgrpID = json.loads(testgrpID_json)
users_json = os.getenv('USERS')
users = json.loads(users_json)
sgt = timezone('Asia/Singapore')
# Get the current date and time in your timezone
now = datetime.now(sgt)
current_date = now.date() - timedelta(days=1)
str_current_date = str(current_date)
formatted_date = current_date.strftime("%d/%m/%Y")
async def updateTeleChannel(text):
print("running inside")
await bot.send_message(chat_id=bbcgrpID, text = text)
# def updateGoogleSheet(str_current_date, completedQuestions):
# # You can implement the logic to update the Google Sheet here
# print("Updating Google Sheet for date:", str_current_date)
# for question in completedQuestions:
# print("Adding question to Google Sheet:", question)
tele_completed_message = formatted_date + '\n' + 'Congrats on completing atleast 2 questions today!' + '\n\n';
print("running")
for user in users :
# print (user['leetcode'])
completedQuestions = []
acceptedSubmissions = requests.get(f"https://alfa-leetcode-api.onrender.com/{user['leetcode']}/acSubmission")
data_dict = json.loads(acceptedSubmissions.text)
for submission in data_dict['submission']:
timestamp = int(submission['timestamp'])
date_time_accepted = datetime.fromtimestamp(timestamp)
date_accepted = str(date_time_accepted.date())
if date_accepted == str_current_date:
# print(submission)
completedQuestions.append(submission['title'])
if len(completedQuestions) >=2 :
# print(len(completedQuestions))
joined_questions = "\n".join(completedQuestions)
tele_completed_message += user['tele'] + '\n' + joined_questions+ '\n\n'
completedQuestions = []
asyncio.run(updateTeleChannel(tele_completed_message))
# updateGoogleSheet(str_current_date, completedQuestions)