Python Inside and Out:
PostgreSQL with PL/Python
http://slides.joshwilliams.name/
Press → key to advance.
Slides should automatically advance, but if not, press the → key.
Python
|
Postgres
|
import antigravity
CREATE OR REPLACE FUNCTION public.get_timeline()
RETURNS SETOF tweet
LANGUAGE plpythonu
AS $function$
import tweepy
authdata = plpy.execute("SELECT * FROM twitter_auth")
auth = tweepy.OAuthHandler(authdata[0]['api_key'], authdata[0]['api_secret'])
auth.set_access_token(authdata[0]['access_token'], authdata[0]['access_secret'])
api = tweepy.API(auth)
tweets = api.home_timeline()
for tweet in tweets:
yield (tweet.user.screen_name.encode("utf-8"), tweet.text.encode("utf-8"), tweet.created_at)
$function$
The end!
Any questions?