-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoftheday.py
More file actions
53 lines (44 loc) · 1.57 KB
/
oftheday.py
File metadata and controls
53 lines (44 loc) · 1.57 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
from groupy.client import Client
import wikipedia
import inflection
import inflect
import random
from dotenv import load_dotenv
from os import getenv
def random_message():
rand_page = wikipedia.random()
# want a bottom level category
page = wikipedia.page(rand_page)
categories = page.categories
filtered_categories = []
for cat in categories:
if ('rticle' not in cat and
'wiki' not in cat and
'Wiki' not in cat and
'date' not in cat and
'source' not in cat and
'stub' not in cat):
filtered_categories.append(cat)
plural_category = random.choice(filtered_categories)
singular_category = ""
inflector = inflect.engine()
for word in plural_category.split(" "):
singular_word = inflector.singular_noun(word)
if singular_word:
singular_category = " ".join([singular_category, singular_word])
else:
singular_category = " ".join([singular_category, word])
singular_category = inflection.titleize(singular_category).strip()
return "Today's {} of the Day is {} {}".format(singular_category, rand_page, page.url)
load_dotenv()
# handle Disambiguation error
message = random_message()
while message is False:
message = random_message()
print(message)
post = input('Post this message? ')
if post in ['y','yes']:
groupme = Client.from_token(getenv('GROUPME_TOKEN'))
dingus_parade = [group for group in groupme.groups.list() if group.id=='19442193'][0]
dingus_parade.post(message)
print("Posted")