Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import os
import binascii
import pyuploadcare
from pyuploadcare import conf
from pyuploadcare.api_resources import File
conf.pub_key = "demopublickey"
conf.secret = "demoprivatekey"
def upload_file(fn):
with open(fn, 'rb') as f:
uf = File.upload(f)
return uf.cdn_url
def handle_line(line):
tpn, name, content_type, image_h, image_w, attachment_size, profile_img = line.strip().split(',')
cdn_url = ''
data = binascii.unhexlify(profile_img[2:])
except TypeError as e:
print 'error processing "{}, {}": {}'.format(tpn, name, e)
with open(name, 'wb') as out:
cdn_url = upload_file(name)
return ','.join([tpn, name, content_type, image_h, image_w, attachment_size, cdn_url])
def handle_file(fn):
with open('out.csv', 'wt') as out:
with open(fn, 'rt') as f:
for line in f:
out.write(handle_line(line) + '\n')
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.