def dataToYandexAudience(): try: print('START') print(" Start uploading segment data") start = datetime.datetime.now() ya = yaaudience.YaAudience(token=ya_token, debug=False) ya_segment_confirmed = None with open(clear_data_phone, 'r') as data_phone, open(clear_data_mail, 'r') as data_mail: for i in [(data_phone, phone_segment_name), (data_mail, mail_segment_name)]: ya_segment_uploaded = ya.segments_upload_file(i[0]) print(ya_segment_uploaded) ya_segment_confirmed = ya.segment_confirm( segment_id=ya_segment_uploaded.id, segment_name=i[1], content_type=p_data_type, hashed=p_data_hashed) print(ya_segment_confirmed) print(" End uploading segment data. Elasped time: " + str(datetime.datetime.now() - start)) except Exception as e: print('!!! Unexpected error: ' + str(e)) finally: print('FINISH')
def lastSegmentsYandexAudience(): ya = yaaudience.YaAudience(token=ya_token) ya_segments = ya.segments() segmentStatus = [ i.FIELDS['status'] for i in ya_segments if i.FIELDS['name'] in [phone_segment_name, mail_segment_name] ] return segmentStatus
def lastSegmentsYandexAudience(): ya = yaaudience.YaAudience(token=ya_token) ya_segments = ya.segments() lastSegments = { ya_segment.FIELDS['id']: ya_segment.FIELDS['name'] for ya_segment in ya_segments if ya_segment.FIELDS['name'] in [phone_segment_name, mail_segment_name] } return lastSegments
def lastSegmentsYandexAudience(): ya = yaaudience.YaAudience(token=ya_token) ya_segments = ya.segments() segmentStatus = [ i.FIELDS['status'] for i in ya_segments if i.FIELDS['name'] in [ phone_segment_name, mail_segment_name, new_phone_segment, new_mail_segment, sleep_phone_segment, sleep_mail_segment ] ] # print(segmentStatus, time.strftime('%H-%M-%S')) return segmentStatus
def allsegmentsYandexAudience(): try: ya = yaaudience.YaAudience(token=ya_token) ya_segments = ya.segments() print(" Segments Count: ", ya_segments.__len__()) print(" Segments Details:") for ya_segment in ya_segments: print(ya_segment) # print(ya_segment.FIELDS['id'], ya_segment.FIELDS['name']) except Exception as e: print('!!! Unexpected error: ' + str(e)) finally: print('FINISH')
def delSegment(segment_id_for_delete): #segment_id_for_delete = '123456789' try: if (segment_id_for_delete is None or segment_id_for_delete == ''): raise Exception('You mast set SEGMENT_ID for deleting!!!') ya = yaaudience.YaAudience(token=ya_token) ya_is_segment_deleted = ya.segment_delete( segment_id=int(segment_id_for_delete)) print(' Is segment deleted? ' + str(ya_is_segment_deleted)) except Exception as e: print('!!! Unexpected error: ' + str(e)) finally: print('FINISH')
def dataToYandexAudience(): try: print("Start uploading segment data") start = datetime.now() ya = yaaudience.YaAudience(token=ya_token, debug=False) ya_segment_confirmed = None newAudience = {} with open(clear_data_phone, 'r') as data_phone, open( clear_data_mail, 'r') as data_mail, open(clear_phoneNew, 'r') as phoneNew, open( clear_phoneSleep, 'r') as phoneSleep, open( clear_mailNew, 'r') as mailNew, open(clear_mailSleep, 'r') as mailSleep: for i in [(data_phone, phone_segment_name), (data_mail, mail_segment_name), (phoneNew, new_phone_segment), (mailNew, new_mail_segment), (phoneSleep, sleep_phone_segment), (mailSleep, sleep_mail_segment)]: ya_segment_uploaded = ya.segments_upload_file(i[0]) # print(ya_segment_uploaded) ya_segment_confirmed = ya.segment_confirm( segment_id=ya_segment_uploaded.id, segment_name=i[1], content_type=p_data_type, hashed=True) newAudience[ya_segment_confirmed. FIELDS['id']] = ya_segment_confirmed.FIELDS['name'] print(newAudience) print("End uploading segment data. Elasped time: " + str(datetime.now() - start)) except Exception as e: print('!!! Unexpected error: ' + str(e)) return { k: v for k, v in newAudience.items() if v in [phone_segment_name, mail_segment_name] }