Created
August 16, 2021 11:40
-
-
Save clarkli86/35c0c4b16517f4bc2924a37f804f2175 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!python3 | |
import requests | |
import json | |
import pprint | |
import csv | |
def create_work_packages(subjects): | |
resp = requests.get('http://openproject.cohda.wireless/api/v3/work_packages/available_projects', | |
headers = {'Content-type':'application/json'}, | |
auth= ('apikey', 'cdd4fb6c5f9df675e866f5b743e249d8bd286e6dd2a2ef4fa21f51e1a04643cb')) | |
if resp.status_code == 200: | |
json_data = json.loads(resp.text) | |
pprint.pprint(json_data) | |
resp = requests.post('http://openproject.cohda.wireless/api/v3/work_packages/form', | |
headers = {'Content-type':'application/json'}, | |
auth= ('apikey', 'cdd4fb6c5f9df675e866f5b743e249d8bd286e6dd2a2ef4fa21f51e1a04643cb')) | |
if resp.status_code == 200: | |
json_data = json.loads(resp.text) | |
pprint.pprint(json_data) | |
created = [] | |
for subject in subjects: | |
# Test work package | |
body = { 'subject': subject[:255], | |
'description': { 'raw' : subject }, | |
'_links': { | |
'project': { | |
'href': '/api/v3/projects/3', | |
}, | |
'type': { | |
'href': '/api/v3/types/4' | |
} | |
} | |
} | |
#resp = requests.post('http://openproject.cohda.wireless/api/v3/work_packages/form', | |
# headers = {'Content-type':'application/json'}, | |
# auth= ('apikey', 'cdd4fb6c5f9df675e866f5b743e249d8bd286e6dd2a2ef4fa21f51e1a04643cb')) | |
# json= body) | |
#print(resp) | |
#if resp.status_code == 200: | |
# json_data = json.loads(resp.text) | |
# payload = json_data['_embedded']['payload'] | |
resp = requests.post('http://openproject.cohda.wireless/api/v3/work_packages', | |
headers = {'Content-type':'application/json'}, | |
auth= ('apikey', 'cdd4fb6c5f9df675e866f5b743e249d8bd286e6dd2a2ef4fa21f51e1a04643cb'), | |
json= body) | |
#print(resp.text) | |
if resp.status_code == 200: | |
pprint.pprint(json_data) | |
elif resp.status_code == 201: | |
print('Created feature for ' + subject) | |
created.append(subject) | |
else: | |
print('Failed to create ' + subject) | |
return | |
print('Number of tickets created : ' + str(len(created))) | |
def import_csv(): | |
subjects = [] | |
with open('requirement.csv', 'r', encoding='utf-8', errors='ignore') as csv_file: | |
line = csv_file.readline() | |
while len(line) > 0: | |
if line.startswith('REQ_PSTS'): | |
parts = line.split(',') | |
subject = parts[0] + ' : ' + ','.join(parts[2:]).replace('\n', '').replace('"', '') | |
subjects.append(subject) | |
line = csv_file.readline() | |
return subjects | |
if __name__ == '__main__': | |
subjects = import_csv() | |
print(subjects) | |
create_work_packages(subjects) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment