ebb/addtoDB.py
2021-01-14 12:26:55 -05:00

51 lines
1.1 KiB
Python

#!/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 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):
#init db
db = TinyDB(pathToDB)
#add to db
db.insert({'path': pathToImage, 'date': 4, 'ssb': SSBidentify})
print("all done, added to db")
#print("heres the whole db")
#print(db.all())
#SEND TO SSB! WOOOO
try:
result = subprocess.call('./ssbpost.sh ' + pathToImage, shell=True)
except:
print 'traceback.format_exc():\n%s' % traceback.format_exc()
exit()
return pathToImage
if __name__ == '__main__':
main()