-
Notifications
You must be signed in to change notification settings - Fork 0
/
rank.py
105 lines (91 loc) · 3.43 KB
/
rank.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
from schedule import every, repeat, run_pending
import os
import tweepy
import time
from dotenv import load_dotenv
import requests
import datetime
from halo import Halo
from discord_webhook import DiscordWebhook
x = datetime.datetime.now()
load_dotenv()
api_key = os.getenv('RIOT_API_KEY')
api_uri = os.getenv('RIOT_API_URI')
consumer_key = os.getenv('TWITTER_API_KEY')
consumer_secret = os.getenv('TWITTER_API_SECRET_KEY')
bot_key = os.getenv('TWITTER_BOT_TOKEN')
bot_secret = os.getenv('TWITTER_BOT_SECRET')
dishook = os.getenv("DISCORD_WEBHOOK")
lower_current_rank = os.getenv("LOWER_CURRENT_RANK")
player_goal_rank = os.getenv("PLAYER_GOAL_RANK")
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(bot_key, bot_secret)
client = tweepy.Client(
consumer_key=consumer_key,
consumer_secret=consumer_secret,
access_token=bot_key,
access_token_secret=bot_secret,
)
api = tweepy.API(auth, wait_on_rate_limit=True)
def check_rank():
# concat the API ENV keys.
api_url = api_uri + "?api_key=" + api_key
# send the request to RIOT GAMES API.
resp = requests.get(api_url)
# parse the response to JSON format.
player_info = resp.json()
# Add the rank tier to the variable rank
division = player_info[0]['tier']
div_rank = player_info[0]['rank']
lp = player_info[0]['leaguePoints']
wins = player_info[0]['wins']
losses = player_info[0]['losses']
# If the rank is PLATINUM send the first message if it's DIAMOND send the second message and end the program.
if division == lower_current_rank:
client.create_tweet(
text=f'NO, AS OF {x.strftime("%c")} SHE IS {division}-{div_rank} WITH {str(int(lp))}LP AND {str(int(losses))} LOSSES https://www.twitch.tv/yoonahkorn')
print('\033[1;92m' + '✔ Tweeted successfully' + '\033[0m', end="\r")
elif division == player_goal_rank:
api.update_status_with_media(
f'SHE FINALLY DID IT !!! - {division}-{div_rank} WITH {lp}LP IT ONLY TOOK HER {str(int(wins))} WINS.', "./assets/letsgo.gif")
print(f"SHE FINALLY REACHED {player_goal_rank}")
webhook = DiscordWebhook(
url=dishook, content='Webhook Message')
response = webhook.execute()
exit()
# define the countdown func.
# @Halo(text='', spinner='dots')
def countdown(t):
while t:
mins, secs = divmod(t, 60)
hours, mins = divmod(mins, 60)
timer = '{:d}:{:02d}:{:02d}'.format(hours, mins, secs)
# print('\033[1;33m' + 'Tweeting in ' + timer + '\033[0m', end='\r')
time.sleep(1)
t -= 1
# spinner = Halo(text='\033[1;33m' + 'Timer is running' + '\033[0m', spinner='dots')
# function call
os.system('cls||clear')
print('\033[1;91m' + 'Starting job...' + '\033[0m')
@repeat(every(1).hours)
def main():
# print('\033[1;32m' + 'Running timer now...' + '\033[0m')
spinner = Halo(text='\033[1;33m'+'Waiting for cooldown.' +
'\033[0m', spinner='dots', color='green')
spinner.start()
countdown(10)
spinner.succeed(text='\n\033[1;34m' + 'Now we send the tweet!' + '\033[0m')
spinner.stop()
# print('\n\033[1;34m' + 'Sending tweet...' + '\033[0m')
# os.system('cls||clear')
check_rank()
print('\n\033[1;37m' + 'Restarting Job...' + '\033[0m')
while True:
try:
run_pending()
time.sleep(1)
except tweepy.TweepError as error:
raise error
exit()
if __name__ == "__main__":
main()