73 lines
1.9 KiB
Python
73 lines
1.9 KiB
Python
#!/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,mintOrGive):
|
|
|
|
# mint
|
|
if mintOrGive == 1:
|
|
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()
|
|
|
|
# else give
|
|
elif mintOrGive == 2:
|
|
try:
|
|
result = subprocess.Popen('./ssb-post.sh give "' + pathToImage + '" ' + description, 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().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 "offline" # Return the blouch
|
|
|
|
# get the key for the post we just made
|
|
key = json_object["key"]
|
|
print (key)
|
|
|
|
return key
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|