#!/usr/bin/python # -*- coding:utf-8 -*- #this script takes a file as an option and adds that file to the db and posts the file to scuttlebutt import optparse import iterparse import traceback import os, sys import subprocess from tinydb import TinyDB, Query def main(): #get options and arguments p = optparse.OptionParser() p.add_option('--file', '-f', action='store', dest='file', help='this needs to be a file path') options, arguments = p.parse_args() if options.file: pathToImage=options.file else: print("you need to provide a file path") exit(1) def addFile(pathToImage, pathToDB, SSBidentify, composite): #init db db = TinyDB(pathToDB) #add to db db.insert({'path': pathToImage, 'date': 4, 'ssb': SSBidentify, 'composite': composite}) print("all done, added to db") #print("heres the whole db") #print(db.all()) #unless you say don't post to ssb, post to ssb if SSBidentify != -1: #SEND TO SSB! WOOOO try: result = subprocess.call('./ssbpost.sh ' + pathToImage, shell=True) except: print('traceback.format_exc():\n%s' % traceback.format_exc()) exit() # get the ssb json from the bash command we just ran newssb=result.stdout.read() # iterate through new ssb posts for decoded in iterparse.parsy(newssb): # get the key for the post we just made key = decoded['key'] return key if __name__ == '__main__': main()