-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbottasks.py
More file actions
138 lines (118 loc) · 4.75 KB
/
bottasks.py
File metadata and controls
138 lines (118 loc) · 4.75 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import requests
import os
import db
import scrape
from dotenv import load_dotenv
from pathlib import Path
from datetime import datetime
load_dotenv(verbose=True)
env_path = Path('.') / '.env'
class Bingo():
def __init__(self):
self.bingo_words = db.get_bingo_words()
def score_list(self):
response = []
for word in self.bingo_words:
if word[1]:
response.append(f'- ~~{word[0]}~~')
else:
response.append(f'- {word[0]}')
return response
def scores(self):
if self.bingo_words:
response = ['!BINGO scores are in!']
response.extend(self.score_list())
response.append(f'{db.count_bingo_words(False)} left to go!')
return "\n".join(response)
return "Nothing yet. Add some words."
def cross(self, word):
if self.bingo_words:
db.update_bingo_words(word, True)
self.bingo_words = db.get_bingo_words()
if db.count_bingo_words(True) == db.count_all_bingo_words():
response = [f'We got {word} !BINGO']
response.extend(self.score_list())
response.append(f'Game over! Game has been reset')
self.reset()
return "\n".join(response)
return f'We got {word} !BINGO'
def info(self, word):
time = db.get_bingo_result(word)
time = datetime.today().date() - time[2]
return f'Total of {time.days} days, since last mention of "{word}"'
def reset(self):
db.reset_bingo_words()
return f'!BINGO is reset!'
def add(self, word):
if not db.get_bingo_result(word):
db.insert_bingo_words(word)
return f'{word} added! {len(self.bingo_words) + 1} words in the !BINGO'
return 'Already in'
def remove(self, word):
if db.get_bingo_result(word):
db.remove_bingo_words(word)
if db.count_bingo_words(True) == db.count_all_bingo_words():
self.bingo_words = db.get_bingo_words()
response = [f'You cheating bastard!']
response.extend(self.score_list())
response.append(f'Game over! Game has been reset')
self.reset()
return "\n".join(response)
return f'{word} removed! {len(self.bingo_words) - 1} words in the !BINGO'
return 'No such word !Bingo'
class Finance():
def __init__(self, symbol, symbol_two = 'USD'):
self.symbol = symbol
self.symbol_two = symbol_two
self.api_key = os.getenv('API_KEY')
def response(self, status):
if status != 200:
return False
return True
def multiply_price(self, price, multi):
return str(float(price) * multi)
def quote_stock(self):
url = 'https://www.alphavantage.co/query?'
response = requests.get(f'{url}function=GLOBAL_QUOTE&symbol={self.symbol}&apikey={self.api_key}')
if not self.response(response.status_code):
return "Whoops, that didn't work!"
response = response.json().get('Global Quote')
if not response:
return "Try different abbrevation?"
else:
response = response['05. price']
response = response.split(".")
response = f"{response[0]}.{response[1][:2]}"
if self.symbol.lower() == "gme":
response = self.multiply_price(response, 2)
response = f'Last closing price for {self.symbol.upper()} is {response} USD!'
return response
def quote_price(self):
url = 'https://www.alphavantage.co/query?'
response = requests.get(f'{url}function=CURRENCY_EXCHANGE_RATE&from_currency={self.symbol}&to_currency={self.symbol_two}&apikey={self.api_key}')
if not self.response(response.status_code):
return "Whoops, that didn't work!"
response = response.json().get('Realtime Currency Exchange Rate')
if not response:
return "Try different abbrevation?"
else:
response = response['5. Exchange Rate']
response = response.split(".")
response = f"{response[0]}.{response[1][:2]}"
response = f'Price for {self.symbol.upper()} is {response} {self.symbol_two}!'
return response
def pixel_planet(planet=None):
if planet:
return scrape.scrape_pixel_planet(planet)
else:
return scrape.scrape_pixel_random()
def depicted(depict=None):
if depict:
return scrape.scrape_depicted(depict)
else:
return scrape.scrape_depicted_random()
def crypto_chickz(chick=None):
if chick:
return scrape.scrape_crypto_chickz(chick)
else:
return scrape.scrape_random_crypto_chickz()