-
Notifications
You must be signed in to change notification settings - Fork 5
/
photo.py
29 lines (22 loc) · 825 Bytes
/
photo.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
#!/usr/bin/env python
# coding=utf-8
import logging
import urllib, urllib2
import api
def save(url, name):
headers = {}
headers['User-Agent'] = 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:22.0) Gecko/20100101 Firefox/22.0'
headers['Accept'] = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
headers['Accept-Language'] = 'zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3'
headers['Accept-Encoding'] = 'gzip, deflate'
headers['Connection'] = 'keep-alive'
req = urllib2.Request(url=url,headers=headers)
get = urllib2.urlopen(req)
pic = get.read()
get.close()
f = file('/home/fanfou/picture/%s.jpg'% name,'w')
f.write(pic)
f.close()
pic_stream = file('/home/fanfou/picture/%s.jpg'% name).read()
code=api.post_photo(pic)
return code