Skip to content

Instantly share code, notes, and snippets.

@d33tah
Created September 30, 2022 19:34
Show Gist options
  • Save d33tah/243d95fdadc460c4838776ba4ca3b22c to your computer and use it in GitHub Desktop.
Save d33tah/243d95fdadc460c4838776ba4ca3b22c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3.8
import logging
import time
import asyncio
import requests
import lxml.html
import nio
async def sendmsg(msg) -> None:
client = nio.AsyncClient("https://matrix.org", "@d33tah-bot1:matrix.org")
await client.login(open('haslo.txt').read().strip())
result = await client.room_send(
room_id=open('room_id.txt').read().strip(),
message_type="m.room.message",
content={
"msgtype": "m.text",
"body": msg,
}
)
logging.info('sent notification(msg=%r) => %s', msg, result)
def notify(msg):
asyncio.get_event_loop().run_until_complete(sendmsg(msg))
def get_money_collected():
h = lxml.html.fromstring(requests.get('https://zrzutka.pl/rfm52e').text)
return h.xpath(
'//* [@data-action="chip-show-amounts"]//div [@class="h3 m-0"]/text()'
)[0].strip().split('\n')[0]
def main():
current_money_collected = money_collected = get_money_collected()
while True:
time.sleep(60)
money_collected = get_money_collected()
if current_money_collected != money_collected:
notify(
'Update ws. zrzutki: aktualnie zebrano: %szł' % money_collected
)
current_money_collected = money_collected
if __name__ == "__main__":
logging.basicConfig(level="DEBUG")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment