-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (51 loc) · 2.03 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
from urllib.request import urlopen
import ssl
import re
from requests.structures import CaseInsensitiveDict
import datetime
import json
from requests_oauthlib import OAuth1Session
## Here we are defining the variables for the Twitter API Authentication ##
consumer_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
consumer_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
access_token ="xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
access_token_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
## Counting the days since JSVP has released their press release ##
today = datetime.date.today()
someday = datetime.date(2022, 7, 27)
diff = today - someday
##print(diff.days)
daycounter = diff.days + 1
context = ssl._create_unverified_context()
url = "https://jsvp.ch/spenden/"
page = urlopen(url,context=context)
## Here we are searching for the Text on the Website ##
gesuchterText = "Bank: UBS Switzerland AG, CH-8098 Zürich"
html_bytes = page.read()
html = html_bytes.decode("utf-8")
webinhalt = re.findall(gesuchterText, html);
## Here we are checking if the text is in the website or not ##
if webinhalt == ['Bank: UBS Switzerland AG, CH-8098 Zürich']:
finaltweet = ( str(daycounter) + " Tage seit heuchlerischem @jungesvp-Aufruf zu @UBSschweiz Boykott, trotzdem haben sie ihr Spendenkonto nach wie vor bei der UBS.")
payload = {"text": "" + finaltweet + ""}
# Make the request
oauth = OAuth1Session(
consumer_key,
client_secret=consumer_secret,
resource_owner_key=access_token,
resource_owner_secret=access_token_secret,
)
# Making the request
response = oauth.post(
"https://api.twitter.com/2/tweets",
json=payload,
)
if response.status_code != 201:
raise Exception(
"Request returned an error: {} {}".format(response.status_code, response.text)
)
print("Response code: {}".format(response.status_code))
json_response = response.json()
print(json.dumps(json_response, indent=4, sort_keys=True))
else:
print("Die UBS ist nicht mehr die Bank der Wahl für die @jungesvp.")