Skip to content

Instantly share code, notes, and snippets.

@ColtonPhillips
Last active August 29, 2015 14:04
Show Gist options
  • Save ColtonPhillips/ff017e9872a1aca66602 to your computer and use it in GitHub Desktop.
Save ColtonPhillips/ff017e9872a1aca66602 to your computer and use it in GitHub Desktop.
Use a python bot to post your flickr pictures to twitter
import tweepy
import flickrapi
from bs4 import BeautifulSoup
from urllib2 import urlopen
from random import choice
import random
import xml.etree.ElementTree as ET
random.seed()
consumer_key=''
consumer_secret=''
access_token_key=''
access_token_secret=''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token_key, access_token_secret)
bot = tweepy.API(auth)
fkey = ""
colton_user_id = "113567215@N05"
flickr = flickrapi.FlickrAPI(fkey)
photos = flickr.photos_search(user_id = colton_user_id, per_page=1000)
soup = BeautifulSoup(ET.tostring(photos, encoding='utf8', method='xml'))
possibilities= soup.find_all('photo')
my_choice = choice(possibilities)
my_id = my_choice['id']
my_title = my_choice['title']
my_photo_url = """https://www.flickr.com/photos/113567215@N05/""" + my_id
tweet = '{title}: {link}'.format(title=my_title, link=my_photo_url)
bot.update_status(tweet)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment