regex, python & twitter

16
webdesigner

Upload: stelian-firez

Post on 05-Dec-2014

2.320 views

Category:

Technology


3 download

DESCRIPTION

Using regular expressions and python to search twitter like a boss

TRANSCRIPT

Page 3: Regex, Python & Twitter

WHAT is REGEX

Regular Expressions

A special text string thatdescribes a search pattern

Page 4: Regex, Python & Twitter

EXAMPLES

Find email address(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])

✔ The Official Standard: RFC 2822

Page 5: Regex, Python & Twitter

EXAMPLES

Find email address easier

\w[\w._]+@[\w.]+[.]\w+{2,4}

Page 6: Regex, Python & Twitter

EXAMPLES

Find email address easier“My email address is: [email protected]

\w[\w._]+@[\w.]+[.]\w+{2,4}

\w[\w._]+@[\w.]+[.]\w+{2,4}“My email address is: [email protected]

\w[\w._]+@[\w.]+[.]\w+{2,4}

“My email address is: [email protected]

“My email address is: [email protected]

Page 7: Regex, Python & Twitter

EXAMPLES

Find email address easier“My email address is: [email protected]

\w[\w._]+@[\w.]+[.]\w+{2,4}

\w[\w._]+@[\w.]+[.]\w+{2,4}

\w[\w._]+@[\w.]+[.]\w+{2,4}

“My email address is: [email protected]

“My email address is: [email protected]

“My email address is: [email protected]

Page 8: Regex, Python & Twitter

WHAT is PYTHON

Life is short, use Python

Page 9: Regex, Python & Twitter

WHO uses PYTHON

Google

Blender 3D

Civilization 4

Page 10: Regex, Python & Twitter

WHY PYTHON

Lots of modules

Easy to read syntax

API wrappers

Great community

Page 11: Regex, Python & Twitter

PYTHON does

click picture to open video

Page 12: Regex, Python & Twitter

SEARCH TWITTERAPI limitations

150 anonymous calls per hour

350 authenticated calls per hour

results from only the past 7 days

max 1500 results

Page 13: Regex, Python & Twitter

SEARCH TWITTERRequirements

minimum Python knowledge

Twitter API wrapper (twython)

Page 14: Regex, Python & Twitter

EXAMPLES

Designers in Antwerpenfrom twython import Twythontwitter = Twython()

search_results = twitter.searchTwitter(q="design", since_id=0, rpp='100', geocode="51.21992,4.39625,10km", page=1)

for tweet in search_results['results']): print tweet[‘id’] print tweet[‘created_at’] print tweet[‘from_user’] print tweet[‘profile_image_url’] print tweet[‘text’]

12

3

456789

10

Page 15: Regex, Python & Twitter

EXAMPLES

Designers in Antwerpenfrom twython import Twythontwitter = Twython()

user_info = twitter.getUserTimeline(id=tweet['from_user'])[0]['user']

print user_info['name']print user_info['time_zone']print user_info['location']print user_info['description']print user_info['url']

12

3

45678