Skip to content

Instantly share code, notes, and snippets.

@jeffehobbs
Created June 27, 2020 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffehobbs/f698761a9f68e3a6da60971f5839e8e2 to your computer and use it in GitHub Desktop.
Save jeffehobbs/f698761a9f68e3a6da60971f5839e8e2 to your computer and use it in GitHub Desktop.
MeetgrinderMA Twitter Bot
# 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