Created
December 21, 2013 19:53
-
-
Save mjtorn/8074107 to your computer and use it in GitHub Desktop.
To push tons of VCF files over MTP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# vim: fileencoding=utf-8 | |
# vcf_to_jolla.py | |
import glob | |
import pymtp | |
import os | |
import sys | |
DST_NAME = 'Documents/Contacts' | |
def main(args): | |
if len(args) != 2: | |
print 'Give the directory containing your vcf files' | |
return 1 | |
dir_ = args[1] | |
mtp = pymtp.MTP() | |
mtp.connect() | |
print 'mtp connected' | |
files = glob.glob1(dir_, '*vcf') | |
print len(files) | |
destination = mtp.create_folder(DST_NAME) | |
print 'Created destination %s' % destination | |
for f in files: | |
src = os.path.join(dir_, f) | |
dst = os.path.join(DST_NAME, f) | |
print '%s -> %s' % (src, dst) | |
try: | |
ret = mtp.send_file_from_file(src, dst) | |
print '\titem_id %d' % ret | |
except Exception, e: | |
mtp.disconnect() | |
raise | |
mtp.disconnect() | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment