def tinderCheck(): user_id = curr_user_id() user = api.users.get(user_ids=str(user_id), fields='sex', access_token=s_token) sex = user[0]['sex'] if sex == 1: sex_str = 'female' elif sex == 2: sex_str = 'male' first_name = user[0]['first_name'] last_name = user[0]['last_name'] if os.path.isdir("/home/jBloodless/mysite/tinder/toA_{0}_{1}_{2}".format( sex_str, first_name, last_name)) or os.path.isdir( "/home/jBloodless/mysite/tinder/toM_{0}_{1}_{2}". format(sex_str, first_name, last_name)) or os.path.isdir( "/home/jBloodless/mysite/tinder/toW_{0}_{1}_{2}".format( sex_str, first_name, last_name)): message = 'Ты вернулся! Хочешь поменять свой профиль или оставить все как было?' buttons = open("/home/jBloodless/mysite/tinderYesNo.json", "r", encoding="UTF-8").read() else: message = 'Обратить на себя внимание можно красивым лицом и метким словцом. Кинь нам свою фотку и расскажи немного о себе, а обо всем остальном я позабочусь.\nСначала отправь фотографию с описанием, через обычную кнопку с самолетиком. При этом клавиатура бота свернется - после отправки ее надо открыть и обязательно нажать Загрузить. Ничего не перепутай!' buttons = open("/home/jBloodless/mysite/tinderInit.json", "r", encoding="UTF-8").read() return message, '', buttons
def counter(): #posts = api.wall.search(owner_id=-177456743, domain = 'test_bot_df', query = '#событие', count = 1, access_token = s_token) #message = posts['items'][0]['text'] user_id = curr_user_id() hist = api.messages.getHistory(peer_id = user_id, group_id=21167006, offset=0, count =1, access_token = token) cand = hist['items'][0]['text'] protect = api.messages.getHistory(peer_id = user_id, group_id=21167006, offset=2, count =1, access_token = token)['items'][0]['text'] if protect=='Наташа Ж.' or protect=='Карина Ч.' or protect=='Марина П.' or protect=='Настя К.' or protect=='Валя Ч.' or protect=='Катя К.' or protect=='Ульяна М.' or protect=='Виолетта П.' or protect=='Лера Л.' or protect=='Наташа У.': message='Ты уже голосовал!' buttons=None return message, '', buttons message='Спасибо! Твой голос учтен.' time.sleep(random.randint(0,10)) wb = load_workbook('/home/votebot/mysite/commands/voting.xlsx') sheet = wb.active b2=sheet.cell(row=2, column=2).value b3=sheet.cell(row=3, column=2).value b4=sheet.cell(row=4, column=2).value b5=sheet.cell(row=5, column=2).value b6=sheet.cell(row=6, column=2).value b7=sheet.cell(row=7, column=2).value b8=sheet.cell(row=8, column=2).value b9=sheet.cell(row=9, column=2).value b10=sheet.cell(row=10, column=2).value b11=sheet.cell(row=11, column=2).value if cand=='Наташа Ж.': b2+=1 sheet.cell(row=2, column=2).value=b2 elif cand=='Карина Ч.': b3+=1 sheet.cell(row=3, column=2).value=b3 elif cand=='Марина П.': b4+=1 sheet.cell(row=4, column=2).value=b4 elif cand=='Настя К.': b5+=1 sheet.cell(row=5, column=2).value=b5 elif cand=='Валя Ч.': b6+=1 sheet.cell(row=6, column=2).value=b6 elif cand=='Катя К.': b7+=1 sheet.cell(row=7, column=2).value=b7 elif cand=='Ульяна М.': b8+=1 sheet.cell(row=8, column=2).value=b8 elif cand=='Виолетта П.': b9+=1 sheet.cell(row=9, column=2).value=b9 elif cand=='Лера Л.': b10+=1 sheet.cell(row=10, column=2).value=b10 elif cand=='Наташа У.': b11+=1 sheet.cell(row=11, column=2).value=b11 wb.save('/home/votebot/mysite/commands/voting.xlsx') #message = str(b2)+' '+str(b3)+' '+str(b4) buttons = None return message, '', buttons
def tinderFirstIter(): path = "/home/jBloodless/mysite/tinder/" user_id = curr_user_id() curr_user = api.users.get(user_ids=str(user_id), access_token=s_token) first_name = curr_user[0]['first_name'] last_name = curr_user[0]['last_name'] user_name = first_name user_surn = last_name while first_name == user_name and last_name == user_surn: first_user = random.choice(os.listdir(path)) name = re.split(r'_', str(first_user)) user_name = name[0] user_surn = name[1] user_dir = "/home/jBloodless/mysite/tinder/{0}_{1}".format( user_name, user_surn) user_pic = "/home/jBloodless/mysite/tinder/{0}_{1}/{0}_{1}.jpg".format( user_name, user_surn) user_inf = "/home/jBloodless/mysite/tinder/{0}_{1}/{0}_{1}.txt".format( user_name, user_surn) id_txt = "/home/jBloodless/mysite/tinder/{0}_{1}/user_id.txt".format( user_name, user_surn) bio = open(user_inf, "r", encoding="UTF-8") id_to_msg = open(id_txt, "r", encoding="UTF-8") message = "@id" + str(id_to_msg.read()) + '\n' + str(bio.read()) server = api.photos.getMessagesUploadServer(peer_id=curr_user_id(), access_token=token) upload_url = server["upload_url"] files = {'photo': open(user_pic, 'rb')} response = requests.post(upload_url, files=files) result = json.loads(response.text) uploadResult = api.photos.saveMessagesPhoto(server=result["server"], photo=result["photo"], hash=result["hash"], access_token=token) attachment = 'photo' + str(uploadResult[0]["owner_id"]) + '_' + str( uploadResult[0]["id"]) #attachment = '' buttons = open("/home/jBloodless/mysite/tinderKeys.json", "r", encoding="UTF-8").read() #message = str(uploadResult[0]["id"]) return message, attachment, buttons
def football1(): user_id = curr_user_id() user = api.users.get(user_ids=str(user_id), access_token = s_token) first_name = user[0]['first_name'] last_name = user[0]['last_name'] hist = api.messages.getHistory(peer_id = user_id, group_id=17379212, offset = 0, count = 1, access_token = token) vote = hist['items'][0]['text'] wb = load_workbook('/home/jBloodless/mysite/commands/football.xlsx') data = (str(user_id), first_name, last_name, vote) sheet=wb.active sheet.append(data) wb.save('/home/jBloodless/mysite/commands/football.xlsx') message = 'Голос учтен!\n Следующая пара — Физтех.Радио против Бакалавров Физтеха' buttons = open("/home/jBloodless/mysite/football2.json", "r", encoding="UTF-8").read() return message, '', buttons
def football3(): user_id = curr_user_id() user = api.users.get(user_ids=str(user_id), access_token=s_token) first_name = user[0]['first_name'] last_name = user[0]['last_name'] hist = api.messages.getHistory(peer_id=user_id, group_id=17379212, offset=0, count=1, access_token=token) vote = hist['items'][0]['text'] wb = load_workbook('/home/jBloodless/mysite/commands/football.xlsx') data = (str(user_id), first_name, last_name, vote) sheet = wb.active sheet.append(data) wb.save('/home/jBloodless/mysite/commands/football.xlsx') message = 'Голос учтен!\n Новая пара — новое противостояние СТЭМов: ЭТО ТьМА против Кванта НГУ!' buttons = open("/home/jBloodless/mysite/football4.json", "r", encoding="UTF-8").read() return message, '', buttons
def football4(): user_id = curr_user_id() user = api.users.get(user_ids=str(user_id), access_token=s_token) first_name = user[0]['first_name'] last_name = user[0]['last_name'] hist = api.messages.getHistory(peer_id=user_id, group_id=17379212, offset=0, count=1, access_token=token) vote = hist['items'][0]['text'] wb = load_workbook('/home/jBloodless/mysite/commands/football.xlsx') data = (str(user_id), first_name, last_name, vote) sheet = wb.active sheet.append(data) wb.save('/home/jBloodless/mysite/commands/football.xlsx') message = 'Голос учтен!\n Коммутируют ли эти команды? Спортивные ученые против Ученых спортсменов!' buttons = open("/home/jBloodless/mysite/football5.json", "r", encoding="UTF-8").read() return message, '', buttons
def footballFinal(): user_id = curr_user_id() user = api.users.get(user_ids=str(user_id), access_token=s_token) first_name = user[0]['first_name'] last_name = user[0]['last_name'] hist = api.messages.getHistory(peer_id=user_id, group_id=17379212, offset=0, count=1, access_token=token) vote = hist['items'][0]['text'] wb = load_workbook('/home/jBloodless/mysite/commands/football.xlsx') data = (str(user_id), first_name, last_name, vote) sheet = wb.active sheet.append(data) wb.save('/home/jBloodless/mysite/commands/football.xlsx') message = 'Что ж, я запомнил твои ответы. Если твой личный осьминог Пауль тебя не подвёл, я тебя хорошенько поздравлю😁' buttons = open("/home/jBloodless/mysite/footballEnd.json", "r", encoding="UTF-8").read() return message, '', buttons
def tinderLike(): user_id = curr_user_id() curr_user = api.users.get(user_ids=str(user_id), fields = 'sex', access_token = s_token) curr_sex = curr_user[0]['sex'] first_name = curr_user[0]['first_name'] last_name = curr_user[0]['last_name'] if curr_sex == 1: sex_str = 'female' elif curr_sex == 2: sex_str = 'male' hist = api.messages.getHistory(peer_id = user_id, group_id=17379212, offset = 1, count = 1, access_token = token) tinderBio = hist['items'][0]['text'] l = tinderBio.find('d') r = tinderBio.find('|') match_id = tinderBio[l+1:r] path = "/home/jBloodless/mysite/tinder/" dirs = os.listdir(path) for i in range(len(dirs)): if dirs[i].endswith('_{0}_{1}_{2}'.format(sex_str, first_name, last_name)): dir_name = re.split(r'_', str(dirs[i])) currdest = dir_name[0] match_user = api.users.get(user_ids=str(match_id), fields = 'sex', access_token = s_token) match_sex = match_user[0]['sex'] if match_sex == 1: match_sex_str = 'female' elif match_sex == 2: match_sex_str = 'male' match_first_name = match_user[0]['first_name'] match_last_name = match_user[0]['last_name'] match_prof=match_first_name+'_'+match_last_name curr_like_f= open("/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/likes/{4}_{5}".format(currdest, sex_str, first_name, last_name, match_first_name, match_last_name), "w") curr_like_f.write(match_id) curr_like_f.close() path = "/home/jBloodless/mysite/tinder/" match_dirs = os.listdir(path) for i in range(len(match_dirs)): if match_dirs[i].endswith('_{0}_{1}_{2}'.format(match_sex_str, match_first_name, match_last_name)): match_dir_name = re.split(r'_', str(match_dirs[i])) matchdest = match_dir_name[0] if os.path.isfile("/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/likes/{4}_{5}".format(matchdest, match_sex_str, match_first_name, match_last_name, first_name, last_name)): unixtime = round(time.time()+10800) wb = load_workbook('/home/jBloodless/mysite/commands/schedule.xlsx', data_only=True) sheet = wb['Лист1'] for i in range (2,45): if sheet.cell(row=i, column=5).value>=unixtime: j=i-1 message_add=str(sheet.cell(row=j, column=3).value) attachment=str(sheet.cell(row=j, column=6).value) break #message = attachment message = 'Взаимный лайк! Совпадение или судьба?... Напиши по ссылке и выясни! Вам даже не стоит ломать голову над местом для свидания, ведь вы на ДФе!\n'+str(message_add)+ '\nЕсли не хватило, то можно начать заново:' message_match = 'Взаимный лайк c @id'+str(user_id)+'! Совпадение или судьба?... Напиши по ссылке и выясни! Вам даже не стоит ломать голову над местом для свидания, ведь вы на ДФе!\n'+str(message_add)+ '\nЕсли не хватило, то можно начать заново:' rnd_seed = random.randint(0, 2147483647) buttons = open("/home/jBloodless/mysite/tinderEnd.json", "r", encoding="UTF-8").read() api.messages.send(random_id=rnd_seed, access_token=token, peer_id=match_id, group_id = 17379212, message=message_match, attachment=attachment, keyboard=buttons) return message, attachment, buttons else: path = "/home/jBloodless/mysite/tinder/" user_id = curr_user_id() curr_user = api.users.get(user_ids=str(user_id), fields = 'sex', access_token = s_token) curr_sex = curr_user[0]['sex'] if curr_sex == 1: curr_sex_str = 'female' elif curr_sex == 2: curr_sex_str = 'male' first_name = curr_user[0]['first_name'] last_name = curr_user[0]['last_name'] dirs = os.listdir(path) for i in range(len(dirs)): if dirs[i].endswith('_{0}_{1}_{2}'.format(curr_sex_str, first_name, last_name)): dir_name = re.split(r'_', str(dirs[i])) currdest = dir_name[0] user_name = first_name user_surn = last_name sex='' dislikes = '/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/dislikes'.format(currdest, curr_sex_str, first_name, last_name) likes = '/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/likes'.format(currdest, curr_sex_str, first_name, last_name) i=0 if currdest=='toA': for i in range(len(os.listdir(path))): if i==len(os.listdir(path))-1: message = 'Пока новых участников не появилось. Но не стоит отчаиваться — это только начало! Возвращайся позже, и чудо обязательно произойдет!' buttons = open("/home/jBloodless/mysite/tinderEnd.json", "r", encoding="UTF-8").read() return message, '', buttons name = re.split(r'_', str(os.listdir(path)[i])) dest = name[0] sex = name[1] user_name=name[2] user_surn=name[3] user_prof = user_name+'_'+user_surn if user_prof not in os.listdir(dislikes) and user_prof not in os.listdir(likes) and first_name!=user_name and last_name!=user_surn: break elif currdest=='toM': for i in range(len(os.listdir(path))): if i==len(os.listdir(path))-1: message = 'Пока новых участников не появилось. Но не стоит отчаиваться — это только начало! Возвращайся позже, и чудо обязательно произойдет!' buttons = open("/home/jBloodless/mysite/tinderEnd.json", "r", encoding="UTF-8").read() return message, '', buttons name = re.split(r'_', str(os.listdir(path)[i])) dest = name[0] sex = name[1] user_name=name[2] user_surn=name[3] user_prof = user_name+'_'+user_surn if user_prof not in os.listdir(dislikes) and user_prof not in os.listdir(likes) and first_name!=user_name and last_name!=user_surn and sex!='female': break elif currdest=='toW': for i in range(len(os.listdir(path))): if i==len(os.listdir(path))-1: message = 'Пока новых участников не появилось. Но не стоит отчаиваться — это только начало! Возвращайся позже, и чудо обязательно произойдет!' buttons = open("/home/jBloodless/mysite/tinderEnd.json", "r", encoding="UTF-8").read() return message, '', buttons name = re.split(r'_', str(os.listdir(path)[i])) dest = name[0] sex = name[1] user_name=name[2] user_surn=name[3] user_prof = user_name+'_'+user_surn if user_prof not in os.listdir(dislikes) and user_prof not in os.listdir(likes) and first_name!=user_name and last_name!=user_surn and sex!='male': break #user_dir = "/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}".format(name[0], sex, user_name, user_surn) user_pic = "/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/{2}_{3}.jpg".format(dest, sex, user_name, user_surn) user_inf = "/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/{2}_{3}.txt".format(dest, sex, user_name, user_surn) id_txt = "/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/user_id.txt".format(dest, sex, user_name, user_surn) bio = open(user_inf, "r", encoding="UTF-8") id_to_msg = open(id_txt, "r", encoding="UTF-8") message = "@id"+str(id_to_msg.read())+'\n'+str(bio.read()) #message = currdest server = api.photos.getMessagesUploadServer(peer_id=curr_user_id(), access_token = token) upload_url = server["upload_url"] files = {'photo': open(user_pic, 'rb')} response = requests.post(upload_url, files=files) result = json.loads(response.text) uploadResult = api.photos.saveMessagesPhoto(server=result["server"], photo=result["photo"], hash=result["hash"], access_token = token) attachment = 'photo'+str(uploadResult[0]["owner_id"])+'_'+str(uploadResult[0]["id"]) #attachment = '' buttons = open("/home/jBloodless/mysite/tinderKeys.json", "r", encoding="UTF-8").read() return message, attachment, buttons
def tinderDislike(): path = "/home/jBloodless/mysite/tinder/" user_id = curr_user_id() curr_user = api.users.get(user_ids=str(user_id), fields='sex', access_token=s_token) curr_sex = curr_user[0]['sex'] if curr_sex == 1: curr_sex_str = 'female' elif curr_sex == 2: curr_sex_str = 'male' first_name = curr_user[0]['first_name'] last_name = curr_user[0]['last_name'] hist = api.messages.getHistory(peer_id=user_id, group_id=17379212, offset=1, count=1, access_token=token) tinderBio = hist['items'][0]['text'] l = tinderBio.find('d') r = tinderBio.find('|') dislike_id = tinderBio[l + 1:r] dirs = os.listdir(path) for i in range(len(dirs)): if dirs[i].endswith('_{0}_{1}_{2}'.format(curr_sex_str, first_name, last_name)): dir_name = re.split(r'_', str(dirs[i])) currdest = dir_name[0] dislike_user = api.users.get(user_ids=str(dislike_id), fields='sex', access_token=s_token) dislike_first_name = dislike_user[0]['first_name'] dislike_last_name = dislike_user[0]['last_name'] curr_dislike_f = open( "/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/dislikes/{4}_{5}". format(currdest, curr_sex_str, first_name, last_name, dislike_first_name, dislike_last_name), "w") curr_dislike_f.write(dislike_id) curr_dislike_f.close() user_name = first_name user_surn = last_name sex = '' dislikes = '/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/dislikes'.format( currdest, curr_sex_str, first_name, last_name) likes = '/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/likes'.format( currdest, curr_sex_str, first_name, last_name) i = 0 if currdest == 'toA': for i in range(len(os.listdir(path))): if i == len(os.listdir(path)) - 1: message = 'Пока новых участников не появилось. Но не стоит отчаиваться — это только начало! Возвращайся позже, и чудо обязательно произойдет!' buttons = open("/home/jBloodless/mysite/tinderEnd.json", "r", encoding="UTF-8").read() return message, '', buttons name = re.split(r'_', str(os.listdir(path)[i])) dest = name[0] sex = name[1] user_name = name[2] user_surn = name[3] user_prof = user_name + '_' + user_surn if user_prof not in os.listdir( dislikes) and user_prof not in os.listdir( likes ) and first_name != user_name and last_name != user_surn: break elif currdest == 'toM': for i in range(len(os.listdir(path))): if i == len(os.listdir(path)) - 1: message = 'Пока новых участников не появилось. Но не стоит отчаиваться — это только начало! Возвращайся позже, и чудо обязательно произойдет!' buttons = open("/home/jBloodless/mysite/tinderEnd.json", "r", encoding="UTF-8").read() return message, '', buttons name = re.split(r'_', str(os.listdir(path)[i])) dest = name[0] sex = name[1] user_name = name[2] user_surn = name[3] user_prof = user_name + '_' + user_surn if user_prof not in os.listdir( dislikes ) and user_prof not in os.listdir( likes ) and first_name != user_name and last_name != user_surn and sex != 'female': break elif currdest == 'toW': for i in range(len(os.listdir(path))): if i == len(os.listdir(path)) - 1: message = 'Пока новых участников не появилось. Но не стоит отчаиваться — это только начало! Возвращайся позже, и чудо обязательно произойдет!' buttons = open("/home/jBloodless/mysite/tinderEnd.json", "r", encoding="UTF-8").read() return message, '', buttons name = re.split(r'_', str(os.listdir(path)[i])) dest = name[0] sex = name[1] user_name = name[2] user_surn = name[3] user_prof = user_name + '_' + user_surn if user_prof not in os.listdir( dislikes ) and user_prof not in os.listdir( likes ) and first_name != user_name and last_name != user_surn and sex != 'male': break #user_dir = "/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}".format(name[0], sex, user_name, user_surn) user_pic = "/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/{2}_{3}.jpg".format( dest, sex, user_name, user_surn) user_inf = "/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/{2}_{3}.txt".format( dest, sex, user_name, user_surn) id_txt = "/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/user_id.txt".format( dest, sex, user_name, user_surn) bio = open(user_inf, "r", encoding="UTF-8") id_to_msg = open(id_txt, "r", encoding="UTF-8") message = "@id" + str(id_to_msg.read()) + '\n' + str(bio.read()) #message = currdest server = api.photos.getMessagesUploadServer(peer_id=curr_user_id(), access_token=token) upload_url = server["upload_url"] files = {'photo': open(user_pic, 'rb')} response = requests.post(upload_url, files=files) result = json.loads(response.text) uploadResult = api.photos.saveMessagesPhoto(server=result["server"], photo=result["photo"], hash=result["hash"], access_token=token) attachment = 'photo' + str(uploadResult[0]["owner_id"]) + '_' + str( uploadResult[0]["id"]) #attachment = '' buttons = open("/home/jBloodless/mysite/tinderKeys.json", "r", encoding="UTF-8").read() #message = str(uploadResult[0]["id"]) return message, attachment, buttons
def tinderFirstIterM(): path = "/home/jBloodless/mysite/tinder/" user_id = curr_user_id() curr_user = api.users.get(user_ids=str(user_id), fields='sex', access_token=s_token) curr_sex = curr_user[0]['sex'] if curr_sex == 1: sex_str = 'female' elif curr_sex == 2: sex_str = 'male' first_name = curr_user[0]['first_name'] last_name = curr_user[0]['last_name'] try: os.rename( "/home/jBloodless/mysite/tinder/toW_{0}_{1}_{2}".format( sex_str, first_name, last_name), "/home/jBloodless/mysite/tinder/toM_{0}_{1}_{2}".format( sex_str, first_name, last_name)) except (OSError, FileNotFoundError): try: os.rename( "/home/jBloodless/mysite/tinder/toA_{0}_{1}_{2}".format( sex_str, first_name, last_name), "/home/jBloodless/mysite/tinder/toM_{0}_{1}_{2}".format( sex_str, first_name, last_name)) except (OSError, FileNotFoundError): pass user_name = first_name user_surn = last_name sex = '' dislikes = '/home/jBloodless/mysite/tinder/toM_{0}_{1}_{2}/dislikes'.format( sex_str, first_name, last_name) likes = '/home/jBloodless/mysite/tinder/toM_{0}_{1}_{2}/likes'.format( sex_str, first_name, last_name) i = 0 for i in range(len(os.listdir(path))): if i == len(os.listdir(path)) - 1: message = 'Пока новых участников не появилось. Но не стоит отчаиваться — это только начало! Возвращайся позже, и чудо обязательно произойдет!' buttons = open("/home/jBloodless/mysite/tinderEnd.json", "r", encoding="UTF-8").read() return message, '', buttons name = re.split(r'_', str(os.listdir(path)[i])) dest = name[0] sex = name[1] user_name = name[2] user_surn = name[3] user_prof = user_name + '_' + user_surn if user_prof not in os.listdir( dislikes ) and user_prof not in os.listdir( likes ) and first_name != user_name and last_name != user_surn and sex != 'female': break #user_dir = "/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}".format(dest, sex, user_name, user_surn) user_pic = "/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/{2}_{3}.jpg".format( dest, sex, user_name, user_surn) user_inf = "/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/{2}_{3}.txt".format( dest, sex, user_name, user_surn) id_txt = "/home/jBloodless/mysite/tinder/{0}_{1}_{2}_{3}/user_id.txt".format( dest, sex, user_name, user_surn) #os.rename("/home/jBloodless/mysite/tinder/{0}_{1}_{2}".format(sex_str, user_name, user_surn), "/home/jBloodless/mysite/tinder/toM_{0}_{1}_{2}".format(sex_str, user_name, user_surn)) bio = open(user_inf, "r", encoding="UTF-8") id_to_msg = open(id_txt, "r", encoding="UTF-8") message = "@id" + str(id_to_msg.read()) + '\n' + str(bio.read()) server = api.photos.getMessagesUploadServer(peer_id=curr_user_id(), access_token=token) upload_url = server["upload_url"] files = {'photo': open(user_pic, 'rb')} response = requests.post(upload_url, files=files) result = json.loads(response.text) uploadResult = api.photos.saveMessagesPhoto(server=result["server"], photo=result["photo"], hash=result["hash"], access_token=token) attachment = 'photo' + str(uploadResult[0]["owner_id"]) + '_' + str( uploadResult[0]["id"]) #attachment = '' buttons = open("/home/jBloodless/mysite/tinderKeys.json", "r", encoding="UTF-8").read() #message = str(uploadResult[0]["id"]) #os.rename("/home/jBloodless/mysite/tinder/{0}_{1}_{2}".format(sex_str, first_name, last_name), "/home/jBloodless/mysite/tinder/toM_{0}_{1}_{2}".format(sex_str, first_name, last_name)) return message, attachment, buttons
def tinderProcess(): user_id = curr_user_id() user = api.users.get(user_ids=str(user_id), fields='sex', access_token=s_token) sex = user[0]['sex'] if sex == 1: sex_str = 'female' elif sex == 2: sex_str = 'male' first_name = user[0]['first_name'] last_name = user[0]['last_name'] #tinderPhoto = api.messages.getHistoryAttachments(peer_id = user_id, group_id=163586862, media_type = 'photo', count = 1, access_token = token) #tinderPhotoURL = tinderPhoto['items'][0]['attachment']['photo']['sizes'][6]['url'] hist = api.messages.getHistory(peer_id=user_id, group_id=17379212, offset=1, count=1, access_token=token) attach_photo = hist['items'][0]['attachments'][0]['photo']['sizes'] width = [None] * len(attach_photo) width_s = [None] * len(attach_photo) for itr in range(len(attach_photo)): width[itr] = attach_photo[itr]['width'] width_s = sorted(width, reverse=True) for nitr in range(len(attach_photo)): if attach_photo[nitr]['width'] == width_s[0]: tinderPhotoURL = attach_photo[nitr]['url'] tinderBio = hist['items'][0]['text'] if os.path.isdir("/home/jBloodless/mysite/tinder/toA_{0}_{1}_{2}/".format( sex_str, first_name, last_name)): shutil.rmtree("/home/jBloodless/mysite/tinder/toA_{0}_{1}_{2}/".format( sex_str, first_name, last_name), ignore_errors=True) elif os.path.isdir( "/home/jBloodless/mysite/tinder/toW_{0}_{1}_{2}/".format( sex_str, first_name, last_name)): shutil.rmtree("/home/jBloodless/mysite/tinder/toW_{0}_{1}_{2}/".format( sex_str, first_name, last_name), ignore_errors=True) elif os.path.isdir( "/home/jBloodless/mysite/tinder/toM_{0}_{1}_{2}/".format( sex_str, first_name, last_name)): shutil.rmtree("/home/jBloodless/mysite/tinder/toM_{0}_{1}_{2}/".format( sex_str, first_name, last_name), ignore_errors=True) try: os.mkdir("/home/jBloodless/mysite/tinder/toA_{0}_{1}_{2}".format( sex_str, first_name, last_name)) except OSError: pass try: os.mkdir("/home/jBloodless/mysite/tinder/toA_{0}_{1}_{2}/likes".format( sex_str, first_name, last_name)) except OSError: pass try: os.mkdir( "/home/jBloodless/mysite/tinder/toA_{0}_{1}_{2}/dislikes".format( sex_str, first_name, last_name)) except OSError: pass photo = urllib.request.urlopen(tinderPhotoURL).read() if os.path.isfile( "/home/jBloodless/mysite/tinder/toA_{0}_{1}_{2}/{1}_{2}.jpg". format(sex_str, first_name, last_name)): os.remove("/home/jBloodless/mysite/tinder/toA_{0}_{1}_{2}/{1}_{2}.jpg". format(sex_str, first_name, last_name)) f = open( "/home/jBloodless/mysite/tinder/toA_{0}_{1}_{2}/{1}_{2}.jpg".format( sex_str, first_name, last_name), "wb") f.write(photo) f.close() if os.path.isfile( "/home/jBloodless/mysite/tinder/toA_{0}_{1}_{2}/{1}_{2}.txt". format(sex_str, first_name, last_name)): os.remove("/home/jBloodless/mysite/tinder/toA_{0}_{1}_{2}/{1}_{2}.txt". format(sex_str, first_name, last_name)) bio = open( "/home/jBloodless/mysite/tinder/toA_{0}_{1}_{2}/{1}_{2}.txt".format( sex_str, first_name, last_name), "w") bio.write(tinderBio) bio.close() idtxt = open( "/home/jBloodless/mysite/tinder/toA_{0}_{1}_{2}/user_id.txt".format( sex_str, first_name, last_name), "w") idtxt.write(str(user_id)) idtxt.close() #message = str(tinderPhotoURL) message = 'Отлично. Жми кнопку, если все готово.' buttons = open("/home/jBloodless/mysite/tinderToPeople.json", "r", encoding="UTF-8").read() return message, '', buttons