check URL for specific string

main
missytake 2024-03-13 16:58:10 +01:00
parent 434a1dd203
commit 90122b86b4
4 changed files with 111 additions and 0 deletions

1
MANIFEST.in Normal file
View File

@ -0,0 +1 @@
include src/greeterbot/avatar.jpg

View File

View File

@ -0,0 +1,110 @@
import time
import requests as r
import deltachat
from deltachat.tracker import ConfigureFailed
from time import sleep
import tempfile
import os
import configargparse
import pkg_resources
def setup_account(addr: str, app_pw: str, data_dir: str, debug: bool) -> deltachat.Account:
"""Create an deltachat account with a given addr/password combination.
:param addr: the email address of the account.
:param app_pw: the SMTP/IMAP password of the accont.
:param data_dir: the directory where the data(base) is stored.
:param debug: whether to show log messages for the account.
:return: the deltachat account object.
"""
try:
os.mkdir(os.path.join(data_dir, addr))
except FileExistsError:
pass
db_path = os.path.join(data_dir, addr, "db.sqlite")
ac = deltachat.Account(db_path)
if debug:
ac.add_account_plugin(deltachat.events.FFIEventLogger(ac))
if not ac.is_configured():
ac.set_config("addr", addr)
ac.set_config("mvbox_move", "0")
ac.set_config("sentbox_watch", "0")
ac.set_config("bot", "1")
ac.set_config("mdns_enabled", "0")
if app_pw != ac.get_config("mail_pw") or not ac.is_configured():
ac.set_config("mail_pw", app_pw)
configtracker = ac.configure()
try:
configtracker.wait_finish()
except ConfigureFailed as e:
print(
"configuration setup failed for %s with password:\n%s"
% (ac.get_config("addr"), ac.get_config("mail_pw"))
)
raise
ac.start_io()
avatar = pkg_resources.resource_filename(__name__, "avatar.jpg")
ac.set_avatar(avatar)
ac.set_config("displayname", "Hello at try.webxdc.org!")
return ac
class GreetBot:
def __init__(self, account: deltachat.Account, contacts: [str]):
self.account = account
self.domain = account.get_config("addr").split("@")[1]
self.curl = {
"url": "https://www.terminland.de/noris-psychotherapie/default.aspx?m=39059&ll=DAl3u&dpp=DAl3u&dlgid=8&step=3&dlg=1&a2291013099=2291025408&mode=frame&css=1'",
"expect": b"F\xc3\xbcr die ADHS-Abkl\xc3\xa4rung stehen derzeit keine freien Termine zur Verf\xc3\xbcgung.<br />Bitte versuchen Sie es zu einem sp\xc3\xa4teren Zeitpunkt noch einmal.",
"headers": {
'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate, br',
'Referer': 'https://www.terminland.de/noris-psychotherapie/default.aspx?m=39059&ll=DAl3u&dpp=DAl3u&step=1&a2291013099=2291025408&mode=frame&css=1&ldlg=1',
'DNT': '1',
'Connection': 'keep-alive',
}
#-H 'Cookie: ASP.NET_SessionId=huwhhoompma2505dsiq31xd0' -H 'Upgrade-Insecure-Requests: 1' -H 'Sec-Fetch-Dest: iframe' -H 'Sec-Fetch-Mode: navigate' -H 'Sec-Fetch-Site: same-origin' -H 'Sec-Fetch-User: ?1'"
}
self.contacts = contacts
def crawl(self):
response = r.get(self.curl['url'], headers=self.curl['headers'])
if self.curl['expect'] not in response.content:
print(str(response.content))
for addr in self.contacts:
print(addr)
def main():
args = configargparse.ArgumentParser()
args.add_argument("--email", help="the bot's email address", env_var="DELTACHAT_ADDR")
args.add_argument("--password", help="the bot's password", env_var="DELTACHAT_PASSWORD")
args.add_argument("--db_path", help="location of the Delta Chat database")
args.add_argument("--show-ffi", action="store_true", help="print Delta Chat log")
ops = args.parse_args()
# ensuring account data directory
if ops.db_path is None:
tempdir = tempfile.TemporaryDirectory(prefix="adhdbot")
ops.db_path = tempdir.name
elif not os.path.exists(ops.db_path):
os.mkdir(ops.db_path)
ac = setup_account(ops.email, ops.password, ops.db_path, ops.show_ffi)
greeter = GreetBot(ac, ["nami@nine.testrun.org"])
print("waiting for ADHD appointment... (and I hate waiting)")
while 1:
greeter.crawl()
sleep(5)
if __name__ == "__main__":
main()

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB