<commit_before>import requests
import json
import ConfigParser, os

# Reference
# http://docs.python-guide.org/en/latest/scenarios/json/
# http://tempo.io/doc/timesheets/api/rest/latest/#1799179586

config = ConfigParser.ConfigParser()
config.read('jira.ini')

siteid = config.get('DEFAULT', 'HOST')
Authorization = config.get('DEFAULT', 'Authorization')
myname = config.get('TEMPO', 'name')
ProjectId = config.getint('TEMPO', 'ProjectId')

# tlscode: TLS-X
# startedtime: YYYY-MM-ddT00:00:00.000+0000
# timespent: in seconds
def createNewWorkLog(tlscode,startedtime,timespent,comment):
    url = "https://%s/rest/tempo-timesheets/3/worklogs/" % (siteid)
    payload = {
        'timeSpentSeconds': timespent,
        'dateStarted': startedtime,
        'comment': comment,
        'issue': {
            'projectId': ProjectId,
            'key': tlscode,
            'remainingEstimateSeconds': 0
        },
        'author': {
            'self': 'https://'+siteid+'/rest/api/2/user?username='+myname,
            'name': myname,
            'displayName': myname,
            'avatar':'https://'+siteid+'/secure/useravatar?size=small&ownerId='+myname
        },
        'worklogAttributes': [],
        'workAttributeValues': []
    }
    headers = {
        'content-type': "application/json",'x-atlassian-token': "no-check",'user-agent': "KISS-TEMPO",'Authorization': Authorization,'origin': "https://"+siteid,'cache-control': "no-cache"
    }

    response = requests.request("POST", url, data=json.dumps(payload), headers=headers)
    return response.status_code

print (createNewWorkLog("TLS-8","2017-02-06T15:00:00.000+0000",3600,"test"));
<commit_msg>finish the csv upload code<commit_after>import requests
import json, csv
import ConfigParser, os, sys

# Reference
# http://docs.python-guide.org/en/latest/scenarios/json/
# http://tempo.io/doc/timesheets/api/rest/latest/#1799179586
# http://swaywang.blogspot.hk/2012/05/pythoncsv.html

config = ConfigParser.ConfigParser()
config.read('jira.ini')

siteid = config.get('DEFAULT', 'HOST')
Authorization = config.get('DEFAULT', 'Authorization')
myname = config.get('TEMPO', 'name')
ProjectId = config.getint('TEMPO', 'ProjectId')

# tlscode: TLS-X
# startedtime: YYYY-MM-ddT00:00:00.000+0000
# timespent: in seconds
def createNewWorkLog(tlscode,startedtime,timespent,comment):
    url = "https://%s/rest/tempo-timesheets/3/worklogs/" % (siteid)
    payload = {
        'timeSpentSeconds': timespent,
        'dateStarted': startedtime,
        'comment': comment,
        'issue': {
            'projectId': ProjectId,
            'key': tlscode,
            'remainingEstimateSeconds': 0
        },
        'author': {
            'self': 'https://'+siteid+'/rest/api/2/user?username='+myname,
            'name': myname,
            'displayName': myname,
            'avatar':'https://'+siteid+'/secure/useravatar?size=small&ownerId='+myname
        },
        'worklogAttributes': [],
        'workAttributeValues': []
    }
    headers = {
        'content-type': "application/json",'x-atlassian-token': "no-check",'user-agent': "KISS-TEMPO",'Authorization': Authorization,'origin': "https://"+siteid,'cache-control': "no-cache"
    }

    response = requests.request("POST", url, data=json.dumps(payload), headers=headers)
    # print status code
    return response.status_code

# startup script
#line = sys.stdin.readline()
# read the csv
f = open(sys.argv[1],'r') if len(sys.argv) > 1 else sys.stdin
for row in csv.reader(f):
    #array = row.split(',')
    #print row[0]
    print(row[0]+": "createNewWorkLog(row[0],row[1],row[2],row[3]))
f.close
# test case
#print (createNewWorkLog("TLS-8","2017-02-06T15:00:00.000+0000",3600,"test"));

{'fraction_non_alphanumeric': 0.17691477885652643, 'fraction_numerical': 0.03182308522114347, 'mean_word_length': 3.550920245398773, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2046087', 'n_tokens_mistral': 1325, 'n_tokens_neox': 1252, 'n_words': 193}