Regex, Python & Twitter
-
Upload
stelian-firez -
Category
Technology
-
view
2.327 -
download
3
description
Transcript of Regex, Python & Twitter
![Page 2: Regex, Python & Twitter](https://reader034.fdocuments.net/reader034/viewer/2022050815/5485f967b47959dd0c8b4fcc/html5/thumbnails/2.jpg)
Picture by Okinawa Soba
![Page 3: Regex, Python & Twitter](https://reader034.fdocuments.net/reader034/viewer/2022050815/5485f967b47959dd0c8b4fcc/html5/thumbnails/3.jpg)
WHAT is REGEX
Regular Expressions
A special text string thatdescribes a search pattern
![Page 4: Regex, Python & Twitter](https://reader034.fdocuments.net/reader034/viewer/2022050815/5485f967b47959dd0c8b4fcc/html5/thumbnails/4.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022050815/5485f967b47959dd0c8b4fcc/html5/thumbnails/5.jpg)
EXAMPLES
Find email address easier
\w[\w._]+@[\w.]+[.]\w+{2,4}
![Page 6: Regex, Python & Twitter](https://reader034.fdocuments.net/reader034/viewer/2022050815/5485f967b47959dd0c8b4fcc/html5/thumbnails/6.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022050815/5485f967b47959dd0c8b4fcc/html5/thumbnails/7.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022050815/5485f967b47959dd0c8b4fcc/html5/thumbnails/8.jpg)
WHAT is PYTHON
Life is short, use Python
![Page 9: Regex, Python & Twitter](https://reader034.fdocuments.net/reader034/viewer/2022050815/5485f967b47959dd0c8b4fcc/html5/thumbnails/9.jpg)
WHO uses PYTHON
Blender 3D
Civilization 4
![Page 10: Regex, Python & Twitter](https://reader034.fdocuments.net/reader034/viewer/2022050815/5485f967b47959dd0c8b4fcc/html5/thumbnails/10.jpg)
WHY PYTHON
Lots of modules
Easy to read syntax
API wrappers
Great community
![Page 12: Regex, Python & Twitter](https://reader034.fdocuments.net/reader034/viewer/2022050815/5485f967b47959dd0c8b4fcc/html5/thumbnails/12.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022050815/5485f967b47959dd0c8b4fcc/html5/thumbnails/13.jpg)
SEARCH TWITTERRequirements
minimum Python knowledge
Twitter API wrapper (twython)
![Page 14: Regex, Python & Twitter](https://reader034.fdocuments.net/reader034/viewer/2022050815/5485f967b47959dd0c8b4fcc/html5/thumbnails/14.jpg)
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](https://reader034.fdocuments.net/reader034/viewer/2022050815/5485f967b47959dd0c8b4fcc/html5/thumbnails/15.jpg)
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
![Page 16: Regex, Python & Twitter](https://reader034.fdocuments.net/reader034/viewer/2022050815/5485f967b47959dd0c8b4fcc/html5/thumbnails/16.jpg)
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