-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
152 lines (121 loc) ยท 4.85 KB
/
main.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
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
from github import Github
from twython import Twython
import requests, datetime, json, os
def push(path, message, content, branch, update=False):
g = Github(os.environ.get('GITHUB_TOKEN'))
repo = g.get_repo("ajlee2006/yourmotheris-data")
source = repo.get_branch("main")
if update: # If file already exists, update it
contents = repo.get_contents(path, ref=branch)
repo.update_file(contents.path, message, content, contents.sha, branch=branch)
else: # If file doesn't exist, create it
repo.create_file(path, message, content, branch=branch)
def bold(input_text):
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
bold_chars = "๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐๐๐
๐๐๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต"
output = ""
for character in input_text:
if character in chars:
output += bold_chars[chars.index(character)]
else:
output += character
return output
def cronjob():
g = Github(os.environ.get('GITHUB_TOKEN'))
repo = g.get_repo("ajlee2006/yourmotheris-data")
response = requests.get("https://wordsapiv1.p.rapidapi.com/words/?partOfSpeech=adjective&random=true",
headers = {
'x-rapidapi-key': os.environ.get('API_KEY'),
'x-rapidapi-host': "wordsapiv1.p.rapidapi.com"
})
data = response.json()
for i in data['results']:
if i['partOfSpeech'] == "adjective":
result = i
break
randomFact = ""
if 'pronunciation' in data:
if 'adjective' in data['pronunciation']:
randomFact = "Pronunciation: /" + data['pronunciation']['adjective'] + "/"
elif 'all' in data['pronunciation']:
randomFact = "Pronunciation: /" + data['pronunciation']['all'] + "/"
else:
randomFact = "Pronunciation: /" + data['pronunciation'] + "/"
randomFact = randomFact.replace("_","-").replace(",","ห").replace("'","ห")
else:
try:
randomFact = "Similar to: " + result['similarTo'][0]
except:
try:
randomFact = "Deriviation: " + result['deriviation'][0]
except:
pass
randomFact = randomFact.replace("'","โ").replace("`","โ")
if 'synonyms' in result:
synonym = "Synonyms: " + ", ".join(result['synonyms'])
else:
synonym = ""
pastdata = requests.get("https://github.com/raw/ajlee2006/yourmotheris-data/main/past.txt").json()['data']
newnum = len(pastdata)+1
time = datetime.datetime.now().astimezone().isoformat()
thedata = [time, newnum, 'Your mother is', data['word'], randomFact, "Definition: " + result['definition'], synonym]
for i in thedata:
print(i)
msg = json.dumps({'data': thedata})
push("current.txt", "Update " + thedata[0] + " " + str(thedata[1]) + " " + thedata[3], msg, "main", update=True)
pastdata.append(thedata)
newpastdata = json.dumps({'data': pastdata})
push("past.txt", "Update " + thedata[0] + " " + str(thedata[1]) + " " + thedata[3], newpastdata, "main", update=True)
requests.post(os.environ.get('WEBHOOK'), data={"content":msg})
twitter = Twython(os.environ.get('TWYTHON_A'),os.environ.get('TWYTHON_B'),os.environ.get('TWYTHON_C'),os.environ.get('TWYTHON_D'))
formattedmessage = '#{}\n{}\n{}\n{}\n{}\n{}'.format(thedata[1], thedata[2], bold(thedata[3]), thedata[4], thedata[5], thedata[6])
twitter.update_status(status=formattedmessage)
asdufhoaisudhfnoun = thedata[3]
#
#
#
#
#
# jonathan
#
#
data = requests.get("https://wordsapiv1.p.rapidapi.com/words/?partOfSpeech=noun&random=true",
headers = {
'x-rapidapi-key': os.environ.get('API_KEY'),
'x-rapidapi-host': "wordsapiv1.p.rapidapi.com"
}).json()
for i in data['results']:
if i['partOfSpeech'] == "noun":
result = i
break
randomFact = ""
if 'pronunciation' in data:
if 'noun' in data['pronunciation']:
randomFact = "Pronunciation: /" + data['pronunciation']['noun'] + "/"
elif 'all' in data['pronunciation']:
randomFact = "Pronunciation: /" + data['pronunciation']['all'] + "/"
else:
randomFact = "Pronunciation: /" + data['pronunciation'] + "/"
randomFact = randomFact.replace("_","-").replace(",","ห").replace("'","ห")
else:
try:
randomFact = "Similar to: " + result['similarTo'][0]
except:
try:
randomFact = "Deriviation: " + result['deriviation'][0]
except:
pass
randomFact = randomFact.replace("'","โ").replace("`","โ")
if 'synonyms' in result:
synonym = "Synonyms: " + ", ".join(result['synonyms'])
else:
synonym = ""
asdfas = 'Haha Jonathan, you are banging (my)'
thedata = [time, asdfas, '**'+data['word']+'**', randomFact, "Definition: " + result['definition'], synonym]
for i in thedata:
print(i)
msg = '\n'.join(thedata[1:])
requests.post(os.environ.get('WEBHOOK_JONATHAN'), data={"content":msg})
requests.post(os.environ.get('WEBHOOK_COMBINED'), data={"content": asdufhoaisudhfnoun + " " + data['word']})
if __name__ == "__main__":
cronjob()