Add webserver capabilities
This enables the script to be either used interactively or from outside services (e.g. userscripts).
This commit is contained in:
parent
6976f919c5
commit
55c15da039
|
@ -10,3 +10,6 @@ userstory_custom_field_name = Platform link
|
||||||
|
|
||||||
initial_task_status = New
|
initial_task_status = New
|
||||||
|
|
||||||
|
[webserver]
|
||||||
|
host = localhost
|
||||||
|
port = 9080
|
||||||
|
|
46
importer.py
46
importer.py
|
@ -1,10 +1,25 @@
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
|
import argparse
|
||||||
import tempfile
|
import tempfile
|
||||||
import requests
|
import requests
|
||||||
import configparser
|
import configparser
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from taiga import TaigaAPI
|
from taiga import TaigaAPI
|
||||||
|
from bottle import run, put, request, response
|
||||||
|
|
||||||
|
try:
|
||||||
|
scriptname = os.path.basename(__file__)
|
||||||
|
except:
|
||||||
|
scriptname = "importer.py"
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog = scriptname,
|
||||||
|
description = "Import printables.com links into your taiga instance",
|
||||||
|
epilog = "The source of this program can be found at: https://git.geekify.de/sqozz/taiga-printable-importer")
|
||||||
|
parser.add_argument("-u", "--url", help="printables.com model url to import into taiga")
|
||||||
|
parser.add_argument("-w", "--enable-webserver", help="enable a webserver to receive URLs continuously", action=argparse.BooleanOptionalAction)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Config parsing
|
# Config parsing
|
||||||
CONFIG=configparser.ConfigParser()
|
CONFIG=configparser.ConfigParser()
|
||||||
|
@ -203,7 +218,24 @@ def get_modelid_from_url(url):
|
||||||
model_id = model_slug.split("-")[0]
|
model_id = model_slug.split("-")[0]
|
||||||
return model_id
|
return model_id
|
||||||
|
|
||||||
link = input("Please paste link: ")
|
@put('/import')
|
||||||
|
def http_import():
|
||||||
|
data = request.body.read()
|
||||||
|
url = data.decode("utf-8")
|
||||||
|
us_url = generate_taiga_userstory(url)
|
||||||
|
response.set_header('Content-Location', us_url)
|
||||||
|
response.status = 201
|
||||||
|
|
||||||
|
def generate_from_cmdline():
|
||||||
|
link = get_url_interactively()
|
||||||
|
us_url = generate_taiga_userstory(link)
|
||||||
|
return us_url
|
||||||
|
|
||||||
|
def get_url_interactively():
|
||||||
|
url = input("Please paste link: ")
|
||||||
|
return url
|
||||||
|
|
||||||
|
def generate_taiga_userstory(link):
|
||||||
model_id = get_modelid_from_url(link)
|
model_id = get_modelid_from_url(link)
|
||||||
print_data = get_printables_print_data(model_id)
|
print_data = get_printables_print_data(model_id)
|
||||||
api = TaigaAPI(host=CONFIG["taiga"]["url"])
|
api = TaigaAPI(host=CONFIG["taiga"]["url"])
|
||||||
|
@ -265,4 +297,14 @@ for stl_file in stl_files:
|
||||||
print(" done.")
|
print(" done.")
|
||||||
|
|
||||||
newstory_url= urllib.parse.urljoin(CONFIG["taiga"]["url"], os.path.join("project", CONFIG["taiga"]["project_slug"], "us", str(story.ref)))
|
newstory_url= urllib.parse.urljoin(CONFIG["taiga"]["url"], os.path.join("project", CONFIG["taiga"]["project_slug"], "us", str(story.ref)))
|
||||||
print("New story created at: {}".format(newstory_url))
|
return newstory_url
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
if bool(args.enable_webserver) == True:
|
||||||
|
run(host=CONFIG["webserver"]["host"], port=CONFIG["webserver"]["port"])
|
||||||
|
sys.exit(0)
|
||||||
|
elif args.url != None:
|
||||||
|
us_url = generate_taiga_userstory(args.url)
|
||||||
|
else:
|
||||||
|
us_url = generate_from_cmdline()
|
||||||
|
print("New story created at: {}".format(us_url))
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
python-taiga
|
python-taiga
|
||||||
requests
|
requests
|
||||||
|
bottle
|
||||||
|
|
Loading…
Reference in a new issue