Skip to content

Instantly share code, notes, and snippets.

@Lysander
Created June 29, 2012 13:18
Show Gist options
  • Select an option

  • Save Lysander/3017858 to your computer and use it in GitHub Desktop.

Select an option

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
#!/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