Upload
stelian-firez
View
2.320
Download
3
Embed Size (px)
DESCRIPTION
Using regular expressions and python to search twitter like a boss
Citation preview
Picture by Okinawa Soba
WHAT is REGEX
Regular Expressions
A special text string thatdescribes a search pattern
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
EXAMPLES
Find email address easier
\w[\w._]+@[\w.]+[.]\w+{2,4}
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]”
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]”
WHAT is PYTHON
Life is short, use Python
WHO uses PYTHON
Blender 3D
Civilization 4
WHY PYTHON
Lots of modules
Easy to read syntax
API wrappers
Great community
SEARCH TWITTERAPI limitations
150 anonymous calls per hour
350 authenticated calls per hour
results from only the past 7 days
max 1500 results
SEARCH TWITTERRequirements
minimum Python knowledge
Twitter API wrapper (twython)
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
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
http://regular-expressions.info
Sams Teach Yourself Regular Expressions in 10 Minutes
Python v2.6.6 documentation
Twython - Python wrapper for the Twitter API
Twitter Search API