def make_repo(TOKEN, USERNAME): # making the repo headers = { 'Authorization' : 'token ' + TOKEN } params = { 'name' : REPO_NAME, 'description' : ('Generated by Remindr to create github issues for '+ USERNAME +' so they finish their TODO list'), 'auto_init' : True } resp = requests.post( BASE_URL+'/user/repos', headers = headers, data = simplejson.dumps(params) ) if resp.status_code != 201: print resp.text return simplejson({ 'message' : "Our github integration broke :(" }), 400 # getting the README resp = requests.get( BASE_URL + '/repos/'+USERNAME+'/'+REPO_NAME+'/readme', headers = headers ) README = simplejson.loads(resp.text) # updating the README params = { 'path' : 'README.md', 'message' : 'adding README explanation', 'content' : base64.b64encode('#TODO LIST\n\nThis is an autogenerated' + ' repo by Remindr to make github issue reminders for u/'+USERNAME), 'sha' : README['sha'] } resp = requests.put( BASE_URL + '/repos/'+USERNAME+'/'+REPO_NAME+'/contents/README.md', headers = headers, data = simplejson.dumps(params) ) if resp.status_code != 200: print resp.text return simplejson({ 'message' : "Our github integration broke :(" }), 400
def make_repo(TOKEN, USERNAME): # making the repo headers = {'Authorization': 'token ' + TOKEN} params = { 'name': REPO_NAME, 'description': ('Generated by Remindr to create github issues for ' + USERNAME + ' so they finish their TODO list'), 'auto_init': True } resp = requests.post(BASE_URL + '/user/repos', headers=headers, data=simplejson.dumps(params)) if resp.status_code != 201: print resp.text return simplejson({'message': "Our github integration broke :("}), 400 # getting the README resp = requests.get(BASE_URL + '/repos/' + USERNAME + '/' + REPO_NAME + '/readme', headers=headers) README = simplejson.loads(resp.text) # updating the README params = { 'path': 'README.md', 'message': 'adding README explanation', 'content': base64.b64encode( '#TODO LIST\n\nThis is an autogenerated' + ' repo by Remindr to make github issue reminders for u/' + USERNAME), 'sha': README['sha'] } resp = requests.put(BASE_URL + '/repos/' + USERNAME + '/' + REPO_NAME + '/contents/README.md', headers=headers, data=simplejson.dumps(params)) if resp.status_code != 200: print resp.text return simplejson({'message': "Our github integration broke :("}), 400
def audit_detail(request): response = {} try: if SESSION_STATUS not in request.session or request.session[ SESSION_STATUS] is not True: return HttpResponse("not authorized") run_log_id = request.POST.get("run_log_id") run_logs = RunLog.objects.filter(id=run_log_id) if len(run_logs) > 0: return HttpResponse(serializers.serialize('json', run_logs)) else: response['result'] = 'fail' return HttpResponse(simplejson.dumps(response)) except Exception as e: print('Exception:', e) response['result'] = 'fail' return HttpResponse(simplejson(response))
def push(topic,message): now=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") try: return simplejson.dumps({"message":db.execute("insert into notification (Message,Topic,Datetime) Values('%s','%s','%s')"%(message,topic,now))}) except Exception as exp: return simplejson({"err": exp})
def response(message="Server side error", code=500): code = int(code) return simplejson({ 'message': message }), code
def post(self, request, *args, **kwargs): adhoc_id = request.POST.get('adhoc_id', '') if request.is_ajax(): AnsibleAdhoc.objects.filter(id=adhoc_id).delete() return HttpResponse(simplejson({'result': '', 'status': 0}))