Advertisement
mspotilas

Sarjakuva päivässä

Jul 1st, 2024 (edited)
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 KB | None | 0 0
  1. #!/usr/bin/python3
  2. import feedparser, re, dateutil.parser, random, datetime, os
  3.  
  4. # ajetaan kerran päivässä
  5.  
  6. feedit = [["#fingerpori", "Fingerpori-sarjakuva", "https://kimmo.suominen.com/stuff/fingerpori-k.xml"],
  7.           ["#fingerpori", "Fingerpori-sarjakuva", "https://kimmo.suominen.com/stuff/fingerpori.xml"],
  8.           ["#haraldhirmuinen", "Harald Hirmuinen -sarjakuva", "https://kimmo.suominen.com/stuff/haraldhirmuinen.xml"],
  9.           ["#viivijawagner", "Viivi ja Wagner -sarjakuva", "https://kimmo.suominen.com/stuff/vw.xml"],
  10.           ["#kamalaluonto", "Kamala luonto -sarjakuva", "https://kimmo.suominen.com/stuff/kamalaluonto-k.xml"]]
  11.  
  12. def escapeshellarg(arg):
  13.     return "\\'".join("'" + p + "'" for p in arg.split("'"))
  14.  
  15.  
  16. def get_rss_content(feed_url):
  17.     feed = feedparser.parse(feed_url)
  18.     image_url = ''
  19.     match = re.search(r'src="(.*?)"', feed.entries[0].summary)
  20.     if match:
  21.         image_url = match[1]
  22.     return feed.entries[0].title, feed.entries[0].link, image_url, dateutil.parser.parse(feed.entries[0].published)
  23.  
  24. today = datetime.datetime.now()
  25.  
  26. random.shuffle(feedit)
  27. for feed in feedit:
  28.     a, url, image, d = get_rss_content(feed[2])
  29.     if d.date() == today.date():
  30.         text = f"Päivän {feed[0]}\n\n{url}"
  31.         image_alt = feed[1]
  32.         print (text, image, image_alt)
  33.         # ^ tuon tilalle twiittaus, tuuttaus, bluuttaus, prööttäys
  34.         #os.system(f"php2bsky/php2bsky.php -t{escapeshellarg(text)} -i{escapeshellarg(image)} -a{escapeshellarg(image_alt)}")
  35.         break
  36.  
Tags: RSS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement