#!/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 json 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 addToDB(pathToImage, pathToDB,composite): #init db db = TinyDB(pathToDB) #add to db db.insert({'path': pathToImage, 'date': 4, 'ssb': '-2', 'composite': composite}) print("all done, added to db") #print("heres the whole db") #print(db.all()) def addToSSB(pathToImage, pathToDB, SSBidentify): #unless you say don't post to ssb, post to ssb if SSBidentify != -1: #SEND TO SSB! WOOOO try: result = subprocess.Popen('./ssbpost.sh ' + pathToImage, shell=True, stdout=subprocess.PIPE, ) 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() print(newssb) #convert string to object json_object = json.loads(newssb) # get the key for the post we just made key = json_object["key"] return key if __name__ == '__main__': main()