Manoj Memana Jayakumar, 3000+ 顶
1. 电影/电视剧 字幕一键下载器
2. IMDb 查询/电子表格生成器
Source on GitHub: imdb
3. theoatmeal.com 连载漫画下载器
Akshit Khurana,4400+ 顶
感谢 500 多个朋友在 Facebook 上为我送出的生日祝福
1…
2
3
1.
# Thanking everyone who wished me on my birthday
4
5
2.
import requests
6
7
3.
import json
8
9
4.
10
11
5.
# Aman s post time
12
13
6. AFTER =
1353233754
14
15
7. TOKEN =
16
17
8.
18
19
9.
def get_posts():
20
21
10.
"""Returns dictionary of id, first names of people who posted on my wall
22
2311. between start and end time"""
24
25
12. query = (
"SELECT post_id, actor_id, message FROM stream WHERE "
26
27
13.
"filter_key = others AND source_id = me() AND "
28
29
14.
"created_time > 1353233754 LIMIT 200")
30
31
15.
32
33
16. payload = { q : query, access_token : TOKEN}
34
35
17. r = requests.get( https://graph.facebook.com/fql , params=payload)
36
37
18. result = json.loads(r.text)
38
39
19.
return result[ data ]
40
41
20.
42
43
21.
def commentall(wallposts):
44
45
22.
"""Comments thank you on all posts"""
46
47
23.
#TODO convert to batch request later
48
49
24.
for wallpost
in wallposts:
50
51
25.
52
53
26. r = requests.get( https://graph.facebook.com/%s %
54
55
27. wallpost[ actor_id ])
56
57
28. url = https://graph.facebook.com/%s/comments % wallpost[ post_id ]
58
59
29. user = json.loads(r.text)
60
61
30. message = Thanks %s :) % user[ first_name ]
62
63
31. payload = { access_token : TOKEN, message : message}
64
65
32. s = requests.post(url, data=payload)
66
67
33.
68
69
34.
print
"Wall post %s done" % wallpost[ post_id ]
70
71
35.
72
73
36.
if __name__ == __main__ :
74
75
37. commentall(get_posts())
76
77…
Tanmay Kulshrestha,3300+ 顶
整理照片
1
import cv2
2
3
import sys
4
5
import os,random,string
6
7
#choices=[ Add a name ]
8
9
import os
10
11current_directory=os.path.dirname(os.path.abspath(__file__))
12
13
from Tkinter
import Tk
14
15
from easygui
import *
16
17
import numpy
as np
18
19x= os.listdir(current_directory)
20
21new_x=[]
22
23testing=[]
24
25
for i
in x:
26
27
if i.find( . )==
-1:
28
29new_x+=[i]
30
31
else:
32
33testing+=[i]
34
35x=new_x
36
37g=x
38
39choices=[ Add a name ]+x
40
41y= range(
1,len(x)+
1)
42
43
def get_images_and_labels():
44
45
global current_directory,x,y,g
46
47
if x==[]:
48
49
return (
False,
False)
50
51image_paths=[]
52
53
for i
in g:
54
55path=current_directory+ +i
56
57
for filename
in os.listdir(path):
58
59final_path=path+ +filename
60
61image_paths+=[final_path]
62
63
# images will contains face images
64
65images = []
66
67
# labels will contains the label that is assigned to the image
68
69labels = []
70
71
for image_path
in image_paths:
72
73
# Read the image and convert to grayscale
74
75img = cv2.imread(image_path,
0)
76
77
# Convert the image format into numpy array
78
79image = np.array(img, uint8 )
80
81
# Get the label of the image
82
83backslash=image_path.rindex( )
84
85underscore=image_path.index( _ ,backslash)
86
87nbr = image_path[backslash+
1:underscore]
88
89t=g.index(nbr)
90
91nbr=y[t]
92
93
# If face is detected, append the face to images and the label to labels
94
95images.append(image)
96
97labels.append(nbr)
98
99
#cv2.imshow("Adding faces to traning set...", image)
100
101
#cv2.waitKey(50)
102
103
# return the images list and labels list
104
105
return images, labels
106
107
# Perform the tranining
108
109
def train_recognizer():
110
111recognizer = cv2.createLBPHFaceRecognizer()
112
113images, labels = get_images_and_labels()
114
115
if images==
False:
116
117
return
False
118
119cv2.destroyAllWindows()
120
121recognizer.train(images, np.array(labels))
122
123
return recognizer
124
125
def get_name(image_path,recognizer):
126
127
global x,choices
128
129
#if recognizer== :
130
131
# recognizer=train_recognizer()
132
133cascadePath =
"haarcascade_frontalface_default.xml"
134
135faceCascade = cv2.CascadeClassifier(cascadePath)
136
137
#recognizer=train_recognizer()
138
139x1=testing
140
141
global g
142
143
print image_path
144
145image = cv2.imread(image_path)
146
147img = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
148
149predict_image = np.array(img, uint8 )
150
151faces = faceCascade.detectMultiScale(
152
153img,
154
155scaleFactor=
1.3,
156
157minNeighbors=
5,
158
159minSize=(
30,
30),
160
161flags = http://cv2.cv.CV_HAAR_SCALE_IMAGE
162
163)
164
165
for (x, y, w, h)
in faces:
166
167f= image[y:y+w,x:x+h]
168
169cv2.imwrite( temp.jpg ,f)
170
171im= temp.jpg
172
173nbr_predicted, conf = recognizer.predict(predict_image[y: y + h, x: x + w])
174
175predicted_name=g[nbr_predicted
-1]
176
177
print
"{} is Correctly Recognized with confidence {}".format(predicted_name, conf)
178
179
if conf>=
140:
180
181
continue
182
183msg= Is this +predicted_name
184
185reply = buttonbox(msg, image=im, choices=[ Yes , No ])
186
187
if reply== Yes :
188
189reply=predicted_name
190
191directory=current_directory+ +reply
192
193
if
not os.path.exists(directory):
194
195os.makedirs(directory)
196
197random_name= .join(random.choice(string.ascii_uppercase + string.digits)
for _
in range(
7))
198
199path=directory+ +random_name+ .jpg
200
201cv2.imwrite(path,f)
202
203
else:
204
205msg =
"Who is this?"
206
207reply = buttonbox(msg, image=im, choices=choices)
208
209
if reply == Add a name :
210
211name=enterbox(msg= Enter the name , title= Training , strip=
True)
212
213
print name
214
215choices+=[name]
216
217reply=name
218
219directory=current_directory+ +reply
220
221
if
not os.path.exists(directory):
222
223os.makedirs(directory)
224
225random_name= .join(random.choice(string.ascii_uppercase + string.digits)
for _
in range(
7))
226
227path=directory+ +random_name+ .jpg
228
229
print path
230
231cv2.imwrite(path,f)
232
233
234
235
# calculate window position
236
237root = Tk()
238
239pos = int(root.winfo_screenwidth() *
0.5), int(root.winfo_screenheight() *
0.2)
240
241root.withdraw()
242
243WindowPosition =
"+%d+%d" % pos
244
245
246
247
# patch rootWindowPosition
248
249rootWindowPosition = WindowPosition
250
251
def detect_faces(img):
252
253
global choices,current_directory
254
255imagePath = img
256
257faceCascade = cv2.CascadeClassifier(cascPath)
258
259image = cv2.imread(imagePath)
260
261gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
262
263faces = faceCascade.detectMultiScale(
264
265gray,
266
267scaleFactor=
1.3,
268
269minNeighbors=
5,
270
271minSize=(
30,
30),
272
273flags = http://cv2.cv.CV_HAAR_SCALE_IMAGE
274
275)
276
277
278
279
print
"Found {0} faces!".format(len(faces))
280
281m=
0
282
283
for (x, y, w, h)
in faces:
284
285m+=
1
286
287padding=
0
288
289f= image[y-padding:y+w+padding,x-padding:x+h+padding]
290
291cv2.imwrite( temp.jpg ,f)
292
293im= temp.jpg
294
295msg =
"Who is this?"
296
297reply = buttonbox(msg, image=im, choices=choices)
298
299
if reply == Add a name :
300
301name=enterbox(msg= Enter the name , title= Training , strip=
True)
302
303
print name
304
305choices+=[name]
306
307reply=name
308
309directory=current_directory+ +reply
310
311
if
not os.path.exists(directory):
312
313os.makedirs(directory)
314
315random_name= .join(random.choice(string.ascii_uppercase + string.digits)
for _
in range(
7))
316
317path=directory+ +random_name+ .jpg
318
319
print path
320
321cv2.imwrite(path,f)
322
323
def new(img,recognizer):
324
325imagePath = current_directory+ +img
326
327
print imagePath
328
329get_name(imagePath,recognizer)
330
331cascPath = haarcascade_frontalface_default.xml
332
333b=
0
334
335os.system(
"change_name.py")
336
337
for filename
in os.listdir(
"."):
338
339b+=
1
340
341
if b%
10==
0
or b==
1:
342
343os.system(
"change_name.py")
344
345recognizer=train_recognizer()
346
347
if filename.endswith( .jpg )
or filename.endswith( .png ):
348
349
print filename
350
351imagePath=filename
352
353
#detect_faces(imagePath)
354
355new(imagePath,recognizer)
356
357os.remove(filename)
358
359raw_input( Done
with this photograph )
Gmail 邮件通知
PNR(Passenger Name Record旅客订座记录,下同) 状态短讯
YouTube 视频下载器
板球比分通知器
WhatsApp 消息
Nalanda 下载器
1
import mechanize,os,urllib2,urllib,requests,getpass,time
2
3start_time = time.time()
4
5
from bs4
import BeautifulSoup
6
7br=mechanize.Browser()
8
9br.open( https://nalanda.bits-pilani.ac.
in/login/index.php )
10
11br.select_form(nr=
0)
12
13
14
15name=
16
17
while name== :
18
19
try:
20
21
print *******
22
23 username=raw_input( Enter Your Nalanda Username: )
24
25 password=getpass.getpass( Password: )
26
27 br.form[ username ]=username
28
29 br.form[ password ]=password
30
31 res=br.submit()
32
33 response=res.read()
34
35 soup=BeautifulSoup(response)
36
37 name=str(soup.find( div ,attrs={
class : logininfo }).a.string)[:
-2]
38
39
except:
40
41
print Wrong Password
42
43f=open( details.txt , w )
44
45f.write(username+ n +password)
46
47f.close()
48
49
print Welcome, +name
50
51
print All the files will be downloaded
in your Drive C
in a folder named
"nalanda"
52
53
#print soup.prettify()
54
55div=soup.find_all( div ,attrs={
class : box coursebox })
56
57
58l=len(div)
59
60a=[]
61
62
for i
in range(l):
63
64 d=div[i]
65
66 s=str(d.div.h2.a.string)
67
68 s=s[:s.find( ( )]
69
70 c=(s,str(d.div.h2.a[ href ]))
71
72 path= c:nalanda +c[
0]
73
74
if
not os.path.exists(path):
75
76 os.makedirs(path)
77
78 a+=[c]
79
80
#print a
81
82overall=[]
83
84
for i
in range(l):
85
86 response=br.open(a[i][
1])
87
88 page=response.read()
89
90 soup=BeautifulSoup(page)
91
92 li=soup.find_all( li ,attrs={
class : section main clearfix })
93
94 x=len(li)
95
96 t=[]
97
98 folder=a[i][
0]
99
100
print Downloading +folder+ files...
101
102 o=[]
103
104
for j
in range(x):
105
106 g=li[j].ul
107
108
#print g
109
110
#raw_input( )
111
112
if g!=
None:
113
114 temp=http://g.li[
class ].split( )
115
116 #raw_input( )
117
118 if temp[1]== resource :
119
120
#print yes
121
122
#print ********************
123
124 o+=[j]
125
126 h=li[j].find( div ,attrs={
class : content })
127
128 s=str(h.h3.string)
129
130 path= c:nalanda +folder
131
132
if path[
-1]== :
133
134 path=path[:
-1]
135
136 path+= +s
137
138
if
not os.path.exists(path):
139
140 os.makedirs(path)
141
142 f=g.find_all( li )
143
144 r=len(f)
145
146 z=[]
147
148
for e
in range(r):
149
150 p=f[e].div.div.a
151
152 q=f[e].find( span ,attrs={
class : resourcelinkdetails }).contents
153
154 link=str(p[ href ])
155
156 text=str(p.find( span ).contents[
0])
157
158 typ=
159
160
if str(q[
0]).find( word )!=
-1:
161
162 typ= .docx
163
164
elif str(q[
0]).find( JPEG )!=
-1:
165
166 typ= .jpg
167
168
else:
169
170 typ= .pdf
171
172
if typ!= .docx :
173
174 res=br.open(link)
175
176 soup=BeautifulSoup(res.read())
177
178
if typ== .jpg :
179
180 di=soup.find( div ,attrs={
class : resourcecontent resourceimg })
181
182 link=di.img[ src ]
183
184
else:
185
186 di=soup.find( div ,attrs={
class : resourcecontent resourcepdf })
187
188 link=di.object[ data ]
189
190
try:
191
192
if
not os.path.exists(path+ +text+typ):
193
194 br.retrieve(link,path+ +text+typ)[
0]
195
196
except:
197
198
print Connectivity Issues
199
200 z+=[(link,text,typ)]
201
202 t+=[(s,z)]
203
204
if t==[]:
205
206
print No Documents
in this subject
207
208 overall+=[o]
209
210
#raw_input( Press any button to resume )
211
212
#print overall
213
214
print Time Taken to Download: +str(time.time()-start_time)+ seconds
215
216
print Do you think you can download all files faster than this :P
217
218
print Closing
in
10 seconds
219
220time.sleep(
10)
我自己的 DC++
公号后台回复「002」,添加助手加入粉丝群
团队打造的计划,敬请期待
好文章,我在看
本文分享自微信公众号 - DataScience(DataScienceTeam)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。
来源:oschina
链接:https://my.oschina.net/u/4159456/blog/4416944