Skip to content

Instantly share code, notes, and snippets.

@Staubgeborener
Last active April 30, 2020 06:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Staubgeborener/c65184841c246a484768b4c252880fe3 to your computer and use it in GitHub Desktop.
Save Staubgeborener/c65184841c246a484768b4c252880fe3 to your computer and use it in GitHub Desktop.
A small bot, which parse some random content from wikipedia and post it on twitter
#(Update from Python2 -> Python3)
from twython import Twython
from urllib.request import urlopen
from importlib import reload
import urllib
import sys
#reload(sys)
#sys.setdefaultencoding('utf8')
# get the keys on https://apps.twitter.com/
C_key = ""
C_secret = ""
A_token = ""
A_secret = ""
myTweet = Twython(C_key,C_secret,A_token,A_secret)
hashtag = " #RaspberryPi"
while True:
url = 'https://en.wikipedia.org/w/api.php?&action=query&format=xml&prop=extracts&generator=s$
html = urllib.request.urlopen(url).read().decode('utf-8')
#html = urlopen(url)
#html = response.read()
#html = html.encode('utf-8')
html = html.split("preserve",1)[1]
html = html[2:-39].replace(""", "'")
if html.find("refers to:") == -1 and html.find("This is a list of") == -1 and html.endswith($
break
html = html + hashtag
#print html
myTweet.update_status(status=html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment