-
Notifications
You must be signed in to change notification settings - Fork 0
/
snoogums.py
247 lines (221 loc) · 8.12 KB
/
snoogums.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
import yagmail
# import arxiv
import feedparser
from bs4 import BeautifulSoup
import requests
import pymupdf
import random
from datetime import datetime, timedelta
from dateutil import tz, parser
try:
from auth import yagmail_auth
except ImportError:
yagmail_auth = "yagmail_auth.json"
random.seed(68419)
clase = [
"class",
"clase",
"fellows",
"darbs",
"comrades",
"friends",
"compatriots",
"colleagues",
"gorls",
"ladies, gentlemen, and members of the jury",
"students",
"scholars",
"scientists",
"researchers",
"academics",
"learners",
"enthusiasts",
"nerds",
"geeks",
"dorks",
"frosh",
"freaks",
"[de]mentees",
"pals",
"lovelies",
"crewmates",
"fellow travelers",
"fellow 4-dimensional sausages",
"bros",
"sisters",
"you cool cats and kittens",
"you beautiful people",
"cuties",
"people",
"folks",
"peeps",
"homies",
"children of the night",
"sleepyheads",
"dreamers",
"believers",
"achievers",
"schemers",
"Techers",
"Caltechians",
"Caltechers",
"Caltechites",
"CalTechers",
"underlings",
"minions",
"subordinates",
"subalterns",
"marmots",
"lemmings",
"squirrel hunters",
"adequates",
"mateys",
"yookeroos",
"amigos",
"compadres",
"sussy frosh",
"impostors",
"delightful individuals",
"smelly meat sacks",
"sentients",
"fellow space travelers",
"friends (and might i just say, you're looking particularly crunchy today)",
"fellow knowledge seekers",
"fellow kids",
"queers",
"queef biscuits",
"you ragtag gang of whippersnappers",
"youths",
"sociopaths",
"schizophrenics",
"fellow neurotypical individuals",
"besties",
]
random.shuffle(clase)
# def arxiv_email():
# # Search for the latest paper in the "astro-ph" category (Astrophysics).
# client = arxiv.Client()
# search = arxiv.Search(query="cat:astro-ph", sort_by=arxiv.SortCriterion.SubmittedDate, sort_order=arxiv.SortOrder.Descending, max_results=10000)
# results = client.results(search)
# papers = list(results)
# if papers:
# for i in range(5):
# # Get a random paper from the search results
# random_paper_index = random.randint(0, len(papers) - 1)
# latest_paper = papers[random_paper_index]
# title = latest_paper.title
# published_datetime = latest_paper.published
# link = latest_paper.pdf_url
# abstract = latest_paper.summary
# print("Title of the latest arXiv astrophysics paper:")
# print(title)
# with yagmail.SMTP("[email protected]", oauth2_file=yagmail_auth) as yag:
# yag.send(
# to="[email protected]",
# subject=title,
# contents=f"""Guys this is huge! Astrophysicists just discovered {title}!!!
# {link}
# {str(published_datetime)[:20]}
# {abstract}
# If this is legit then we just proved Einstein wrong!!! \(°Ω°)/ ☭ ༼つಠ益ಠ༽つ ─=≡ΣO))""",
# )
# else:
# print("No astrophysics papers found")
def another_revolution_email():
with open("Another Revolution.txt", "r", encoding="ascii", errors="ignore") as f:
contents = f.readlines()
# find a random line that starts with either "KAT" or "HENRY" (case sensitive)
line = ""
while not line.startswith(("KAT", "HENRY")):
line = random.choice(contents)
line_index = contents.index(line)
line_plus_first_word = " ".join(line.split(" ", 4)[:-1])
with yagmail.SMTP("[email protected]", oauth2_file=yagmail_auth) as yag:
yag.send(
to="[email protected]",
subject=f"Another Revolution Sneak Preview #{line_index}",
contents=f"""
{line_plus_first_word}
---
"Do you like beans? Do you like logical conundrums? Do you like explosions in petri dishes?"
Please come join me and Skyler Ware G6 as we struggle with friendship, ambition and world events on stage in Beckman Institute Auditorium opening WEDNESDAY 11/8 at 7:30pm for three shows:
Wednesday November 8, 7:30pm
Thursday November 9, 7:30pm
Friday November 10, 4:30pm
Location: Beckman Institute Auditorium
Kat and Henry, two graduate students (one a botanist from a working-class family and the other a theoretical physicist from a wealthy one) are forced to share a lab at Columbia University in 1968. Amid interpersonal differences, a campus devolving into political chaos, and the uncertainty and turmoil of the outside world, they each discover what it’s like to be thrown into someone else’s orbit.
"""
)
def tech_email():
d = feedparser.parse("https://campuspubs.library.caltech.edu/cgi/exportview/publication/California_Tech/California_Tech/RSS2/California_Tech_California_Tech.xml")
index_current = len(d['entries']) - get_index() - 1
index = min(index_current, read_index())
title = d['entries'][index]['title']
libpage = requests.get(d['entries'][index]['id'])
if libpage.status_code == 200:
soup = BeautifulSoup(libpage.content, 'html.parser')
# look for the first <a> tag with the text 'PDF' or 'pdf'
pdf = soup.find('a', string=lambda x: x and 'pdf' in x.lower())
if pdf:
print(pdf['href'])
# Fetch the PDF file
pdf_response = requests.get(pdf['href'])
if pdf_response.status_code == 200:
with open('temp.pdf', 'wb') as f:
f.write(pdf_response.content)
# Open the PDF file
pdf_document = pymupdf.open('temp.pdf')
# Get the first page
first_page = pdf_document.load_page(0)
# Convert the first page to an image
pix = first_page.get_pixmap()
pix.save('first_page.png')
with yagmail.SMTP("[email protected]", oauth2_file=yagmail_auth) as yag:
yag.send(
to="[email protected]",
subject=f"[DEI 169] From the Archives #{index}: {title}",
contents=[
f"Hi {clase[index]},\n",
f"READING ASSIGNMENT #{index}:\n====================\n\n{title}\n\n{pdf['href']}\n\n",
yagmail.inline("first_page.png")
]
)
increment_index()
def get_index():
pacific_tz = tz.gettz('America/Los_Angeles')
current_time_utc = datetime.now(tz=tz.tzutc())
current_time_pacific = current_time_utc.astimezone(pacific_tz)
beginning_of_november = datetime(2024, 11, 1, 0, 0, 0, tzinfo=pacific_tz)
time_difference = current_time_pacific - beginning_of_november
# Calculate the number of 20-minute intervals
i = time_difference.total_seconds() // (20 * 60)
assert i >= 0, "It is not November yet"
return int(i)
def read_index():
try:
with open("index.txt", "r") as f:
return int(f.read())
except FileNotFoundError:
return 0
def increment_index():
with open("index.txt", "a") as f:
f.write(str(read_index() + 1))
def error_email(e):
with yagmail.SMTP("[email protected]", oauth2_file=yagmail_auth) as yag:
yag.send(
to="[email protected]",
subject=f"Guutz's code sucks",
contents=[
"Guutz's code sucks and threw this error:",
str(e),
"https://github.com/guutz/pg_templates/blob/main/snoogums.py"
]
)
if __name__ == "__main__":
# another revolution email if date is before 11/10/2023 4:30pm UTC-8
# if datetime.now().astimezone(tz.gettz("America/Los_Angeles")) < datetime(2023, 11, 10, 16, 30, 0, tzinfo=tz.gettz("America/Los_Angeles")):
# another_revolution_email()
try:
tech_email()
except Exception as e:
error_email(e)