forked from mach24/pin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmove.py
30 lines (24 loc) · 825 Bytes
/
move.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
from mypinnings import database
import urllib
import os
from PIL import Image
import traceback
db = database.connect_db()
def upload_image(url, pid):
ext = os.path.splitext(url)[1].lower()
urllib.urlretrieve(url, 'static/tmp/%d%s' % (pid, ext))
if ext != '.png':
img = Image.open('static/tmp/%d%s' % (pid, ext))
img.save('static/tmp/%d.png' % pid)
temp_pins = list(db.select('temp_pins'))
for y in temp_pins:
try:
new_id = db.insert('pins', description=y.title, user_id=20, board_id=12, link=y.link, category=4)
try:
upload_image(y.image, new_id)
except:
db.delete('pins', where='id = $id', vars={'id': new_id})
db.delete('temp_pins', where='id = $id', vars={'id': y.id})
except:
traceback.print_exc()
continue