hey it kinda works!
This commit is contained in:
67
addtoDB.py
Normal file
67
addtoDB.py
Normal file
@ -0,0 +1,67 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding:utf-8 -*-
|
||||
|
||||
#this script takes a file as an option and adds that file scuttlebutt
|
||||
# originally from ebb, modified for custodisco
|
||||
|
||||
import optparse
|
||||
import traceback
|
||||
import os, sys
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
|
||||
|
||||
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 addToSSB(pathToImage,description):
|
||||
#SEND TO SSB! WOOOO
|
||||
try:
|
||||
result = subprocess.Popen('./ssb-post.sh mint "' + description + '" ' + pathToImage, shell=True, stdout=subprocess.PIPE, )
|
||||
except:
|
||||
print('traceback.format_exc():\n%s' % traceback.format_exc())
|
||||
exit()
|
||||
|
||||
# for testing:
|
||||
#print(result)
|
||||
|
||||
# get the ssb json from the bash command we just ran
|
||||
#newssb=result.stdout.read()
|
||||
##chatgpt's version:
|
||||
newssb = result.stdout.read().decode() # decode bytes to string
|
||||
print(newssb)
|
||||
|
||||
# CHECK that newssb is _anything_ if ssb-server isn't running that may show as garbage that will crash the program
|
||||
if len(newssb) == 0:
|
||||
print("String is empty")
|
||||
|
||||
#convert string to object
|
||||
# Make sure it's valid JSON before loading
|
||||
try:
|
||||
json_object = json.loads(newssb)
|
||||
except json.JSONDecodeError:
|
||||
print("Invalid JSON")
|
||||
return "blouch" # Return the blouch
|
||||
|
||||
# get the key for the post we just made
|
||||
key = json_object["key"]
|
||||
print (key)
|
||||
|
||||
return key
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user