Guest User

Untitled

a guest
Nov 16th, 2019
91
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import re
  2. import feedparser
  3. from datetime import datetime
  4. from collections import defaultdict
  5.  
  6. my_dict = defaultdict(lambda: {"articles": [],"count": 0})
  7.  
  8. def increment(key_string, entry):
  9. yeet = my_dict[key_string]
  10. yeet["articles"].append(entry.title)
  11. yeet["count"] = yeet["count"] + 1
  12. my_dict[key_string] = yeet
  13.  
  14. def get_bylines():
  15.  
  16. regex_string = "B([yY]) (\w+) (\w+)"
  17.  
  18. regex_two = "B([yY]) (\w+) (\w+) AND (\w+) (\w+)"
  19.  
  20. regex_three = "B([yY]) (\w+) (\w+), (\w+) (\w+) AND (\w+) (\w+)"
  21.  
  22. d = datetime.now()
  23.  
  24. if d.day <= 15:
  25. start_str = f"{d.month}/1/{d.year}"
  26. end_str = f"{d.month}/15{d.year}"
  27. else:
  28. start_str = f"{d.month}/16/{d.year}"
  29. end_str = f"{d.month}/{d.day}/{d.year}"
  30.  
  31. start_str = "11/1/2019"
  32. end_str = "11/15/2019"
  33.  
  34. campus_search_string = f"https://www.purdueexponent.org/search/?q=&nsa=eedition&t=article&c[]=campus&l=100&s=start_time&sd=desc&f=rss&d1={start_str}&d2={end_str}"
  35. city_search_string = f"https://www.purdueexponent.org/search/?q=&nsa=eedition&t=article&c[]=city_state&l=100&s=start_time&sd=desc&f=rss&d1={start_str}&d2={end_str}"
  36.  
  37. campus_feed = feedparser.parse(campus_search_string)
  38. city_feed = feedparser.parse(city_search_string)
  39.  
  40. entry_list = campus_feed.entries + city_feed.entries
  41.  
  42. for e in entry_list:
  43. m = re.match(regex_three, e.author)
  44. if m is None:
  45. n = re.match(regex_two, e.author)
  46. if n is None:
  47. o = re.match(regex_string, e.author)
  48. if o is None:
  49. print("Nothing found for: " + e.author)
  50. pass
  51. else:
  52. key_string = f"{o.group(2)} {o.group(3)}"
  53. increment(key_string, e)
  54. else:
  55. key_string = f"{n.group(2)} {n.group(3)}"
  56. increment(key_string, e)
  57.  
  58. key_string = f"{n.group(4)} {n.group(5)}"
  59. increment(key_string, e)
  60. else:
  61. key_string = f"{m.group(2)} {m.group(3)}"
  62. increment(key_string, e)
  63.  
  64. key_string = f"{m.group(4)} {m.group(5)}"
  65. increment(key_string, e)
  66.  
  67. key_string = f"{m.group(6)} {m.group(7)}"
  68. increment(key_string, e)
  69.  
  70. search_string_city = f"https://www.purdueexponent.org/search/?q=&nsa=eedition&t=article&c[]=city_state&l=100&s=start_time&sd=desc&f=rss&d1={start_str}&d2={end_str}"
  71.  
  72. feed = feedparser.parse(search_string_city)
  73.  
  74. return my_dict
  75.  
  76.  
  77. res = get_bylines()
  78.  
  79. for name in res.keys():
  80. print(f"{name}: {res[name]}")
RAW Paste Data