Created
June 29, 2012 13:18
-
-
Save Lysander/3017858 to your computer and use it in GitHub Desktop.
Little fun script, that prints out an happy or unhappy smiley based upton the "+-/1" messages in the "I am goging to pycon"-Thread: http://www.python-forum.de/viewtopic.php?f=5&t=29566
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| import re | |
| from collections import defaultdict | |
| import requests | |
| from lxml import html | |
| URL = r"http://www.python-forum.de/viewtopic.php?f=5&t=29566" | |
| SMILEY = {True: ":-)", False: ":-("} | |
| def main(): | |
| root = html.fromstring(requests.get(URL).text) | |
| result = defaultdict(int) | |
| for post in root.xpath("//div[@class='postbody']/text()"): | |
| pattern = re.search(r"([+-])1", post) | |
| if pattern: | |
| result[pattern.groups()[0]] += 1 | |
| # print(result) | |
| print(SMILEY[result["+"] >= result["-"]]) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment