-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhue.py
293 lines (217 loc) · 9.14 KB
/
hue.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
import string
import pygame
from pygame.locals import *
import urllib2
import re
nameOf1 = 'Amitabh_Bachchan'
nameOf2 = 'Aishwarya_Rai_Bachchan'
str1 = "http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=jsonfm&titles="+ nameOf1 +"&rvsection=0"
str2 = "http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=jsonfm&titles="+ nameOf2 +"&rvsection=0"
url1 = urllib2.urlopen(str1);
url2 = urllib2.urlopen(str2);
orig = url1.read();
#print orig;
#print type(k);
rela = ["SPOUSE", "CHILD", "RELATIVE", "NAME"]
help1_relation = []
help2_relation = []
size = 4
list_1 = [[] for x in range(size)]
list_2 = [[] for x in range(size)]
for main_number in range(1,3):
if main_number==1:
url1 = urllib2.urlopen(str1);
orig = url1.read();
else:
url2 = urllib2.urlopen(str2);
orig = url2.read();
pos1 = orig.find('Infobox')
#print pos1;
temp = orig[pos1:];
pos2 = temp.find("'''");
#print pos2;
info_text = orig[pos1:pos2+pos1]
#print info_text;
pos_name = info_text.find('name');
if(pos_name != -1):
#print("NAME :"),
name = info_text[pos_name + len('name ='):]
for i in range(len(name)):
if ord(name[i])>=65 and ord(name[i])<=90:
break;
name = name[i: (name.find('n|')) -1 ]
#name = format_name(info_text[pos_name+7:], len(info_text[pos_name+7:]))
#print name
if main_number==1:
list_1[3].append(name)
else:
list_2[3].append(name)
#name = info_text[: (info_text[pos_name:].find('n|'))]
#print name[0:len(name)-1]
#print name[0:len(name)-1]
pos_relative = info_text.find('relatives');
if(pos_relative != -1):
#print("RELATIVE :"),
#print pos_relative + len('relatives =')
#print (info_text[pos_relative:].find('n|')) + pos_relative + 100
relative = info_text[pos_relative + len('relatives ='): (info_text[pos_relative:].find('n|')) + pos_relative+ 100]
#assuming maximum 4 relatives
#print relative
n1 = relative.find('[[');
n2 = relative.find(']]');
#print relative[n1+2:n2]
if main_number==1:
list_1[2].append(relative[n1+2:n2])
sk1 = relative.find("(");
sk2 = relative.find(")");
help1_relation.append(relative[sk1+1:sk2])
else:
list_2[2].append(relative[n1+2:n2])
sk1 = relative.find("(");
sk2 = relative.find(")");
help2_relation.append(relative[sk1+1:sk2])
if n2!=-1:
relative = relative[n2+2:]
n1 = relative.find('[[');
n2 = relative.find(']]');
#print relative[n1+2:n2]
if main_number==1:
list_1[2].append(relative[n1+2:n2])
sk1 = relative.find("(");
sk2 = relative.find(")");
help1_relation.append(relative[sk1+1:sk2])
else:
list_2[2].append(relative[n1+2:n2])
sk1 = relative.find("(");
sk2 = relative.find(")");
help2_relation.append(relative[sk1+1:sk2])
#print relative[0:len(relative)-1]
pos_spouse = info_text.find('spouse');
if(pos_spouse != -1):
#print("SPOUSE :"),
spouse = info_text[pos_spouse + len('spouse ='): (info_text[pos_spouse:].find('n|')) + len('spouse =')+pos_spouse]
n1 = spouse.find('[[');
n2 = spouse.find(']]');
#print spouse[n1+2:n2]
if main_number==1:
list_1[0].append(spouse[n1+2:n2])
else:
list_2[0].append(spouse[n1+2:n2])
regex = r'[' + "*" + r']';
pattern = re.compile(regex)
pos_parents = info_text.find('parents');
if(pos_parents != -1):
#print("PARENTS :"),
parents = info_text[pos_parents + len('parents ='): (info_text[pos_parents:].find('n|')) + pos_parents]
n1 = parents.find('[[');
n2 = parents.find(']]');
#print parents[n1+2:n2]
tit = re.findall(pattern, parents)
#print tit
#print parents[0:len(parents)-1]
pos_children = info_text.find('children');
if(pos_children != -1):
#print("CHILDREN :"),
children = info_text[pos_children + len('children ='): (info_text[pos_children:].find('n|')) + pos_children]
n1 = children.find('[[');
n2 = children.find(']]');
#print children[n1+2:n2]
if main_number==1:
list_1[1].append(children[n1+2:n2])
else:
list_2[1].append(children[n1+2:n2])
#print children[0:len(children)-1]
#print "LIST-1",
#print list_1
#print help1_relation
#print "LIST-2",
#print list_2
#print help2_relation
str1 = "http://live.dbpedia.org/page/" + nameOf1
str2 = "http://live.dbpedia.org/page/" + nameOf2
#str2 = "http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvprop=content&format=jsonfm&titles="+ nameOf2 +"&rvsection=0"
url1 = urllib2.urlopen(str1);
url2 = urllib2.urlopen(str2);
orig1 = url1.read();
orig2 = url2.read();
pos_1 = [m.start() for m in re.finditer('dbpprop:starring', orig1)]
pos_2 = [m.start() for m in re.finditer('dbpprop:starring', orig2)]
l1 = len(pos_1)
l2 = len(pos_2)
movies_1 = ["" for i in xrange(l1)]
movies_2 = ["" for i in xrange(l2)]
#print len(x1)
for i in range(l1):
pos2 = orig1.find('<small>dbpedia</small>:', pos_1[i]) + len('<small>dbpedia</small>:')
pos3 = orig1.find('</a>', pos2)
movies_1[i] = orig1[pos2: pos3]
#print movies_1
for i in range(l2):
pos2 = orig2.find('<small>dbpedia</small>:', pos_2[i]) + len('<small>dbpedia</small>:')
pos3 = orig2.find('</a>', pos2)
movies_2[i] = orig2[pos2: pos3]
#print movies_2
#print '\n\n\n'+ "The movies which they have in common are:"
to_print = " "
for i in range(size):
for j in range(size):
for k in range(len(list_1[i])):
for l in range(len(list_2[j])):
if list_1[i][k] == list_2[j][l]:
if i==3:
to_print = to_print + nameOf1 + " is " + rela[j] + " of " + nameOf2
elif j==3:
to_print = to_print + rela[i] + " of " + nameOf1 + " is " + nameOf2
else:
to_print = to_print + rela[i] + " of " + nameOf1 + " is " + rela[j] + " of " + nameOf2
to_print = to_print + ' '+ "The movies which they have in common are:"
if 1:
for i in range(l1):
for j in range(l2):
if movies_1[i] == movies_2[j]:
to_print = to_print + movies_2[j] + ','
print to_print
pygame.init()
# Set size of pygame window.
screen=pygame.display.set_mode((640,480))
# Create empty pygame surface.
background = pygame.Surface(screen.get_size())
# Fill the background white color.
background.fill((255, 255, 255))
# Convert Surface object to make blitting faster.
background = background.convert()
# Copy background to screen (position (0, 0) is upper left corner).
screen.blit(background, (0,0))
#to_print = "adsdsfdfbfngngnghghykykm dga sgsf egsdagdgdg ghdhfghrG idon ewskfnd ffsf fsfsfskvnsvskfslfslfa"
mainloop = True
while mainloop:
# Do not go faster than this framerate.
for event in pygame.event.get():
# User presses QUIT-button.
if event.type == pygame.QUIT:
mainloop = False
elif event.type == pygame.KEYDOWN:
# User presses ESCAPE-Key
if event.key == pygame.K_ESCAPE:
mainloop = False
# Print framerate and playtime in titlebar.
text = "CONNEXION"
pygame.display.set_caption(text)
font = pygame.font.Font(None, 45)
text = font.render(to_print, 1, (10, 10, 10))
leap = 36
i=0;
k=0;
while 1:
if leap*(k+1)>=len(to_print):
text = font.render(to_print[leap*k :], 1, (10, 10, 10))
background.blit(text, (0, k*25))
break;
text = font.render(to_print[leap*k :leap*(k+1)], 1, (10, 10, 10))
background.blit(text, (0,k*25))
k = k+1;
screen.blit(background, (0, 0))
#Update Pygame display.
pygame.display.flip()
# Finish Pygame.
pygame.quit()