Last active
April 30, 2020 06:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#(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