This repository has been archived by the owner on Jun 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathihate.py
executable file
·115 lines (98 loc) · 2.52 KB
/
ihate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env python3
import time
import sys
import requests
from lxml import etree
osearch_templates = {
'DuckDuckGo': 'https://duckduckgo.com/ac/?q={}&type=list',
'Google': 'https://suggestqueries.google.com/complete/search?output=firefox&q={}',
'Bing': 'https://api.bing.com/osjson.aspx?query={}',
'Yahoo': 'https://search.yahoo.com/sugg/os?command={}&output=fxjson&fr=opensearch'
}
religions = [
'Catholics',
'Christians',
'Atheists',
'Jehovah\'s Witnesses',
'Mormons'
'Muslims',
'Hindu',
'Buddhists',
'Lutherans',
'Baptists',
'Religion',
'Sunnis',
'Shiites',
'Justin Bieber'
]
races = [
'Blacks',
'Whites',
]
sexual = [
'Gays',
'Lesbians',
'Homosexuals',
'Straights',
'Bisexuals',
]
politics = [
'Feminists',
'Liberals',
'Conservatives',
'Democrats',
'Communists',
'George Washington',
'Abraham Lincoln',
'Hitler',
'George W Bush',
'Bush',
'Barack Obama',
'Obama'
]
def opensearch_ihate(s, template, hate):
q = 'I hate ' + hate
json = s.get(template.format(q + ' ')).json()
if len(json) < 2:
return False
suggestions = json[1]
if suggestions:
return True
return False
def get_ethnicities():
html = requests.get('https://en.wikipedia.org/wiki/List_of_contemporary_ethnic_groups').content
html = etree.HTML(html)
tbody = html.xpath('//table[contains(.//th/text(), "Ethnicity")]/tbody')[0]
ret = tbody.xpath('./tr[position() > 1]/td[1]/a/text()')
return ret
def get_nationalities():
html = requests.get('https://en.wikipedia.org/wiki/Lists_of_people_by_nationality').content
html = etree.HTML(html)
tbody = html.xpath('//div[@id="mw-content-text"]/div[2]')[0]
ret = tbody.xpath('.//a/text()')
return ret
def main():
hates = []
if len(sys.argv) == 1:
ethnicities = get_ethnicities()
nationalities = get_nationalities()
hates += ethnicities
hates += nationalities
hates += religions
hates += races
hates += sexual
hates += politics
else:
hates.append(' '.join(sys.argv[1:]))
hates = list(set(hates))
hates.sort()
s = requests.Session()
for hate in hates:
ihate = []
for name, template in osearch_templates.items():
if opensearch_ihate(s, template, hate):
ihate.append(name)
ihate = ' '.join(ihate)
print('I hate {}: {}'.format(hate, ihate))
if __name__ == '__main__':
main()