-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweet.py
59 lines (47 loc) · 1.72 KB
/
tweet.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
from datetime import datetime
from dayfinder import get_approximation_day
import sys
import math
test = "test" in sys.argv
if test:
print("Running in test mode. Tweets will not be sent")
else:
import twitter
import mastodon
now = datetime.now()
approx_day = get_approximation_day(now.day, now.month)
if approx_day is not None:
tweet = "Happy " + str(approx_day) + " Approximation Day!"
tweet2 = str(approx_day) + " = " + str(approx_day.value)
tweet2 += "\n\n"
tweet2 += "Today = " + str(now.day) + "/" + str(now.month)
if now.day % now.month == 0:
tweet2 += " = " + str(now.day // now.month)
else:
tweet2 += " = " + str(now.day / now.month)
tweet2 += "\n\n"
error = abs((now.day / now.month) - approx_day.value)
error /= (now.day / now.month)
tweet2 += "error = "
digits = 10 ** 4
tweet2 += str(math.floor(error * 100 * digits) / digits) + "%"
if test:
print("If not in test mode, I would've tweeted:")
print(" ", tweet)
print(" ", "\n ".join(tweet2.split("\n")))
else:
import config as c
tw = twitter.Twitter(auth=twitter.OAuth(
c.token, c.secret, c.consumer_key, c.consumer_secret))
mdon = mastodon.Mastodon(
access_token="mdon.secret", api_base_url="https://mathstodon.xyz")
result = tw.statuses.update(status=tweet)
mresult = mdon.toot(tweet)
print("updated status: " + tweet)
tw.statuses.update(
status="@" + c.username + " " + tweet2,
in_reply_to_status_id=result["id"])
mdon.status_post(
"@" + c.username + " " + tweet2,
in_reply_to_id=mresult["id"])
print("updated status: " + tweet2)