gpt4 book ai didi

python tinder 机器人不会发送消息 - 网络错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:53:20 25 4
gpt4 key购买 nike

我正在组装一个自动向右滑动的 python Tinder 机器人,我还希望它能够发送消息。一切正常,除了匹配时应该发送消息,但实际上却没有。我已经尝试了我能想到的所有可能的代码组合,但无济于事。我和我 future 所有的 Tinder 匹配(如果我能找到的话)都将非常感谢任何帮助解决这个问题的帮助。

该代码调用一个名为 talk(user_id) 的函数,该函数应执行 POST curl 请求。

代码:

1,1  Top# encoding: utf8
import argparse
from datetime import datetime
import json
from random import randint
import requests
import sys
from time import sleep


headers = {
'app_version': '519',
'platform': 'ios',
}


fb_id = 'XXXXXXXXXXXXX'
fb_auth_token = 'XXXXXXXXXXXX'


class User(object):
def __init__(self, data_dict):
self.d = data_dict

@property
def user_id(self):
return self.d['_id']

@property
def name(self):
return self.d['name']

@property
def ago(self):
raw = self.d.get('ping_time')
if raw:
d = datetime.strptime(raw, '%Y-%m-%dT%H:%M:%S.%fZ')
secs_ago = int(datetime.now().strftime("%s")) - int(d.strftime("%s"))
if secs_ago > 86400:
return u'{days} days ago'.format(days=secs_ago / 86400)
elif secs_ago < 3600:
return u'{mins} mins ago'.format(mins=secs_ago / 60)
else:
return u'{hours} hours ago'.format(hours=secs_ago / 3600)

return '[unknown]'

@property
def bio(self):
try:
x = self.d['bio'].encode('ascii', 'ignore').replace('\n', '')[:50].strip()
except (UnicodeError, UnicodeEncodeError, UnicodeDecodeError):
return '[garbled]'
else:
return x

@property
def age(self):
raw = self.d.get('birth_date')
if raw:
d = datetime.strptime(raw, '%Y-%m-%dT%H:%M:%S.%fZ')
return datetime.now().year - int(d.strftime('%Y'))

return 0

def __unicode__(self):
return u'{name} ({age}), {distance}km, {ago}'.format(
name=self.d['name'],
age=self.age,
distance=self.d['distance_mi'],
ago=self.ago
)

def auth_token(fb_auth_token, fb_user_id):
h = headers
h.update({'content-type': 'application/json'})
req = requests.post(
'https://api.gotinder.com/auth',
headers=h,
data=json.dumps({'facebook_token': fb_auth_token, 'facebook_id': fb_user_id})
)
try:
return req.json()['token']
except:
return None


def recommendations(auth_token):
h = headers
h.update({'X-Auth-Token': auth_token})
r = requests.get('https://api.gotinder.com/user/recs', headers=h)
if r.status_code == 401 or r.status_code == 504:
raise Exception('Invalid code')
print r.content

if not 'results' in r.json():
print r.json()

for result in r.json()['results']:
yield User(result)


def like(user_id):
try:
u = 'https://api.gotinder.com/like/%s' % user_id
d = requests.get(u, headers=headers, timeout=0.7).json()
except KeyError:
raise
else:
return d['match']


def nope(user_id):
try:
u = 'https://api.gotinder.com/pass/%s' % user_id
requests.get(u, headers=headers, timeout=0.7).json()
except KeyError:
raise

def like_or_nope():
return 'nope' if randint(1, 100) == 31 else 'like'


def talk(user_id):
try:
u = 'https://api.gotinder.com/user/matches/%s' % user_id
requests.post(
u,
data=json.dumps=({'message': 'Hey! How are you?'})
)
except KeyError:
raise


if __name__ == '__main__':

parser = argparse.ArgumentParser(description='Tinder automated bot')
parser.add_argument('-l', '--log', type=str, default='activity.log', help='Log file destination')

args = parser.parse_args()

print 'Tinder bot'
print '----------'
matches = 0
liked = 0
nopes = 0

while True:
token = auth_token(fb_auth_token, fb_id)

if not token:
print 'could not get token'
sys.exit(0)

for user in recommendations(token):
if not user:
break

print unicode(user)

if user.name == 'Tinder Team':
print('Out of swipes, pausing one hour...')
sleep(3601)

else:
try:
action = like_or_nope()
if action == 'like':
print ' -> Like'
match = like(user.user_id)
if match:
print ' -> Match!'
conversation = talk(user.user_id)
if conversation:
print ' -> Message Sent!'

with open('./matched.txt', 'a') as m:
m.write(user.user_id + u'\n')

with open('./liked.txt', 'a') as f:
f.write(user.user_id + u'\n')

else:
print ' -> random nope :('
nope(user.user_id)
except:
print 'networking error %s' % user.user_id

s = float(randint(10000, 20000) / 1000)
sleep(s)`

最佳答案

检查下面的代码是否有帮助。我使用 pynder 包来剖析 API,但我想逻辑仍然是一样的。

session._post('/user/matches/' + match['id'], {"message": "Hey! How are you?"})

post 函数的工作原理如下:-

def _post(self, url, data={}):
return self._request("post", url, data=data)

直接尝试这个方法data={message} 它对我有用,非常好。

关于python tinder 机器人不会发送消息 - 网络错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35664915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com