Created
June 27, 2020 22:33
-
-
Save jeffehobbs/f698761a9f68e3a6da60971f5839e8e2 to your computer and use it in GitHub Desktop.
MeetgrinderMA Twitter Bot
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
# meetgrinderMA.py | jeffehobbs@gmail.com | June 2020 | |
# detect meetings, tweet 'em out | |
import json, requests, feedparser, tweepy, time | |
from bs4 import BeautifulSoup | |
# globals | |
FEED = 'https://www.northamptonma.gov/RSSFeed.aspx?ModID=65&CID=City-Council-95' | |
DOMAIN = 'https://northamptonma.gov' | |
# twitter api keys (obfuscated in this gist -- get your own!) | |
CONSUMER_KEY = '###' | |
CONSUMER_SECRET = '###' | |
ACCESS_KEY = '###' | |
ACCESS_SECRET = '###' | |
def parseFeed(FEED): | |
d = feedparser.parse(FEED) | |
#print(d['feed']['title']) | |
#print(d['entries'][0]['link']) | |
parseUrl(d['entries'][0]['link'], d['entries'][0]['title']) | |
def parseUrl(url, title): | |
req = requests.get(url) | |
soup = BeautifulSoup(req.content, 'html.parser') | |
raw_link = soup.find("a", {"title":title}) | |
link = DOMAIN + raw_link['href'] | |
#print(title + '\n' + link) | |
tweetLink(link, title) | |
def tweetLink(url, title): | |
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) | |
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET) | |
api = tweepy.API(auth) | |
output = title + '\n' + url | |
try: | |
api.update_status(status=output) | |
print("\nTWEETED UPDATE:\n" + str(output) + '\n') | |
time.sleep(10) | |
except: | |
print('\nALREADY TWEETED:\n' + str(output) + '\n') | |
if __name__ == "__main__": | |
parseFeed(FEED) | |
# fin |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment