def applyChangesAdhs(connection, cyclos): cyclosLogger.info(LOG_HEADER + '[-] '+'applyChangesAdhs') with open(os.path.dirname(os.path.abspath(__file__)) +'/json/'+jsonfile) as data_file: datas = json.load(data_file) for k, v in datas.items(): for changes in v: if (changes['dbtochange'] == "cyclos"): if (changes['type'] == "delete"): print("delete "+k) id = cyclos.getIdFromEmail(k) if (id == False): cyclosLogger.info(LOG_HEADER + '[-] impossible de trouver '+k) else: cyclos.disableUser(id) if (changes['type'] == "modify"): print("modify "+k) #id = cyclos.getIdFromEmail(k) #data={changes['field']: changes['newvalue']} data={"name": changes['newvalue'], "username": k, "email": k} cyclos.putUser(k, data) if (changes['type'] == "create"): print("create "+k) infos = changes['infos'] result_json = cyclos.addUser(infos['email'], infos['name'], infos['email']) print (result_json)
now = datetime.now() last_hour_date_time = datetime.now() - timedelta(days=2) url = cfg.ha['url'] + '?from=' + last_hour_date_time.strftime( "%Y-%m-%dT%H:%M:%S") params = {'results_per_page': 1000} r = requests.get(url, auth=(cfg.ha['user'], cfg.ha['password']), params=params) result = json.loads(r.text) if 'resources' in result: resources = result['resources'] for resource in resources: if (re.match('.*paiements.*', resource['url_receipt'])): if (resource['id'] not in listtransactions): print resource['id'] + " " + resource['payer_email'].encode( 'utf-8') + " " + str(resource['amount']) accountID = cyclos.getIdFromEmail(resource['payer_email']) res = cyclos.setPaymentSystemtoUser( accountID, resource['amount'], "Transaction via HelloAsso Id : " + resource['id']) tmp = {resource['date']: res['transactionNumber']} listtransactions[resource['id']] = tmp print listtransactions with open(cfg.ha['transactions'], 'w') as outfile: json.dump(listtransactions, outfile, indent=4, sort_keys=False, separators=(',', ':'))
def setTransactionstoCyclos(self): cyclos = Cyclos() with open(cfg.ha['transactions']) as data_file: listtransactions = json.load(data_file) now = datetime.now() last_hour_date_time = datetime.now() - timedelta(days=2) #url = cfg.ha['url']+'?from='+last_hour_date_time.strftime("%Y-%m-%dT%H:%M:%S") #url = 'https://api.helloasso.com/v5/organizations/le-florain' #params = {} #headers = {'Content-type': 'application/json', 'Authorization': 'Bearer '+token} #resp = requests.get(url, params=params, headers=headers) now = datetime.now() last_hour_date_time = datetime.now() - timedelta(days=90) #url = cfg.ha['url']+'?from='+last_hour_date_time.strftime("%Y-%m-%dT%H:%M:%S") url = cfg.ha[ 'url'] + '/payments' + '?pageSize=1000&from=' + last_hour_date_time.strftime( "%Y-%m-%dT%H:%M:%S") params = {} headers = { 'Content-type': 'application/json', 'Authorization': 'Bearer ' + self.token } try: resp = requests.get(url, params=params, headers=headers) except requests.exceptions.Timeout: paiementLogger.error(LOG_HEADER + '[-] Timeout') except requests.exceptions.TooManyRedirects: paiementLogger.error(LOG_HEADER + '[-] TooManyRedirects') except requests.exceptions.RequestException as e: paiementLogger.error(LOG_HEADER + '[-] Exception') raise SystemExit(e) if (resp.status_code != "200"): paiementLogger.error(LOG_HEADER + '[-] status not 200 HelloAsso') exit result = json.loads(resp.text) for data in result['data']: #print data['order']['id'] #print listtransactions #print data['order']['id'] not in listtransactions paiementLogger.info(LOG_HEADER + '[-] ' + str(data)) if (str(data['id']) not in listtransactions): if ((data['order']['formSlug'] == 'change-florain-numerique-credit-unitaire') or (data['order']['formSlug'] == 'test-change-florain-numerique-credit-mensuel')): #for item in data['items']: # amount = item['amount'] amount = data['amount'] accountID = cyclos.getIdFromEmail(data['payer']['email']) amountCyclos = amount / 100 res = {} if (accountID != False): if (data['state'] == "Authorized"): paiementLogger.info('') msglog = LOG_HEADER + '[-] ' if (self.simulate): msglog += 'SIMULATE' paiementLogger.info(msglog + ' PAIEMENT : id:' + accountID + ' amount:' + str(amountCyclos) + ' helloassoid:' + str(data['order']['id'])) if (not self.simulate): res = cyclos.setPaymentSystemtoUser( accountID, amountCyclos, "Transaction via HelloAsso Id : " + str(data['order']['id'])) #print(res) res_object = json.loads(res.text) #print(res_object['transactionNumber']) #res = {} #res['transactionNumber']="XXX" if ('transactionNumber' in res_object): tmp = { 'date': data['date'], 'orderdate': data['order']['date'], 'orderid': data['order']['id'], 'transactionCyclos': res_object['transactionNumber'], 'formulaire': data['order']['formSlug'], 'email': data['payer']['email'], 'state': data['state'], 'paymentMeans': data['paymentMeans'], 'amount': amountCyclos } else: if ('text' in res): paiementLogger.error( LOG_HEADER + '[-] ' + (res.text).encode('utf-8')) else: paiementLogger.error(LOG_HEADER + '[-] ' + str(res)) tmp = { 'date': data['date'], 'orderdate': data['order']['date'], 'orderid': data['order']['id'], 'transactionCyclos': 'None', 'formulaire': data['order']['formSlug'], 'email': data['payer']['email'], 'state': data['state'], 'paymentMeans': data['paymentMeans'], 'amount': amountCyclos } else: tmp = { 'date': data['date'], 'orderdate': data['order']['date'], 'orderid': data['order']['id'], 'formulaire': data['order']['formSlug'], 'email': data['payer']['email'], 'amount': amountCyclos, 'state': data['state'], 'paymentMeans': data['paymentMeans'], 'error': 'paiement not Authorized' } else: tmp = { 'date': data['date'], 'orderdate': data['order']['date'], 'orderid': data['order']['id'], 'formulaire': data['order']['formSlug'], 'email': data['payer']['email'], 'amount': amountCyclos, 'state': data['state'], 'paymentMeans': data['paymentMeans'], 'error': 'email not found' } listtransactions[data['id']] = tmp print("") #print listtransactions with open(cfg.ha['transactions'], 'w') as outfile: json.dump(listtransactions, outfile, indent=4, sort_keys=False, separators=(',', ':'))