def updateStyle(self): log.i("APP", "Update style!") try: with open('./style.css', 'r') as cssfile: self.setStyleSheet(cssfile.read()) except Exception as e: log.e("APP", "Update style Exception")
def get_fb_user_id(self, fb_token, log_to_widget=True, thread_update_signal=None): fb_id = fb_auth_token.get_fb_id(fb_token) log.e("FB_ID", "Gotten fb user id: " + str(fb_id), log_to_widget) return fb_id
def get_messages(self, match_data=None, count=100, page_token=None, log_to_widget=True, thread_update_signal=None): # https://api.gotinder.com/v2/matches/5e762f611d443d01005c86975ea8db0a728e280100783a6e/messages?locale=en&count=100 # https://api.gotinder.com/v2/matches/5cae0e962d5de015002490965ea8db0a728e280100783a6e/messages?locale=en&count=100&page_token= try: path = '/v2/matches/%s/messages?locale=en&count=%s' % ( match_data["_id"], count) if page_token is not None: path += "&page_token=%s" % page_token r = requests.get(self.host + path, headers=self.headers) print("Messages url: " + str(self.host + path)) r_json = r.json() if 'next_page_token' in r_json['data']: new_data = self.get_messages(match_data, 100, r_json['data']['next_page_token'], log_to_widget, thread_update_signal) for message in new_data['data']['messages']: message[ 'page_token'] = page_token # This will be needed to get messages r_json['data']['messages'] = r_json['data'][ 'messages'] + new_data['data']['messages'] r_json["match_id"] = match_data["_id"] return r_json except requests.exceptions.RequestException as e: log.e("API", "Something went wrong. Could not get messages:" + str(e), log_to_widget)
def like(self, person_id, log_to_widget=True, thread_update_signal=None): try: url = self.host + '/like/%s' % person_id r = requests.get(url, headers=self.get_headers) return r.json() except requests.exceptions.RequestException as e: log.e("API", "Something went wrong. Could not like:" + str(e), log_to_widget)
def get_fb_access_token(self, email, password, log_to_widget=True, thread_update_signal=None): token = fb_auth_token.get_fb_access_token(email, password) log.e("TOKEN", "Gotten token: " + str(token), log_to_widget) return token
def unmatch(self, match_id, log_to_widget=True, thread_update_signal=None): try: url = self.host + '/user/matches/%s' % match_id r = requests.delete(url, headers=self.headers) return r.json() except requests.exceptions.RequestException as e: log.e("API", "Something went wrong. Could not unmatch person:" + str(e), log_to_widget)
def updateProfileData(self, downloaded_data): try: with open(self.profile_file, 'w') as fp: json.dump(downloaded_data, fp) log.i("API", "Profile data written to: " + self.profile_file) except Exception as e: log.e("API", "Exception saving " + self.profile_file + " json: " + str(e)) pass
def get_matches(self, log_to_widget=True, thread_update_signal=None): try: url = self.host + '/v2/matches' r = requests.get(url, headers=self.headers) return r.json() except requests.exceptions.RequestException as e: log.e( "API", "Something went wrong. Could not get your match iself.page_tokennfo:" + str(e), log_to_widget)
def see_friends(self, log_to_widget=True, thread_update_signal=None): try: url = self.host + '/group/friends' r = requests.get(url, headers=self.headers) return r.json()['results'] except requests.exceptions.RequestException as e: log.e( "API", "Something went wrong. Could not get your Facebook friends:" + str(e), log_to_widget)
def get_recs_v2(self, log_to_widget=True, thread_update_signal=None): ''' This works more consistently then the normal get_recommendations becuase it seeems to check new location ''' try: url = self.host + '/v2/recs/core?locale=en-US' r = requests.get(url, headers=self.headers) return r.json() except Exception as e: log.e("API", 'excepted', log_to_widget)
def save_to_yaml(self): try: print("Saving yaml...") log.i("LOGIN_F", self.config_file) log.d("LOGIN_F", self.config) with open(self.config_file, 'w') as fy: yaml.dump(self.config, fy) self.statusBar.showMessage("Credentials Saved to " + str(self.config_file)) except Exception as e: log.e("LOGIN_F", "Exceptipn: " + str(e))
def get_self(self, log_to_widget=True, thread_update_signal=None): ''' Returns your own profile data ''' try: url = self.host + '/profile' r = requests.get(url, headers=self.headers) return r.json() except requests.exceptions.RequestException as e: log.e("API", "Something went wrong. Could not get your data:" + str(e), log_to_widget)
def updateData(self, list_to_fill, downloaded_data, file_path): if list_to_fill is not None and isinstance(list_to_fill, list): list_to_fill.append(downloaded_data) data_to_dump = list_to_fill else: data_to_dump = downloaded_data try: with open(file_path, 'w') as fp: json.dump(data_to_dump, fp) log.i("API", "Data written to: " + file_path) except Exception as e: log.e("API", "Exception saving " + file_path + " json: " + str(e))
def get_person(self, id, log_to_widget=True, thread_update_signal=None): ''' Gets a user's profile via their id ''' try: url = self.host + '/user/%s' % id r = requests.get(url, headers=self.headers) return r.json() except requests.exceptions.RequestException as e: log.e("API", "Something went wrong. Could not get that person:" + str(e), log_to_widget)
def match_info(self, match_id, log_to_widget=True, thread_update_signal=None): try: url = self.host + '/matches/%s' % match_id r = requests.get(url, headers=self.headers) return r.json() except requests.exceptions.RequestException as e: log.e( "API", "Something went wrong. Could not get your match info:" + str(e), log_to_widget)
def fast_match_info(self, log_to_widget=True, thread_update_signal=None): try: url = self.host + '/v2/fast-match/preview' r = requests.get(url, headers=self.headers) count = r.headers['fast-match-count'] # image is in the response but its in hex.. return count except requests.exceptions.RequestException as e: log.e( "API", "Something went wrong. Could not get your fast-match count:" + str(e), log_to_widget)
def reset_real_location(self, log_to_widget=True, thread_update_signal=None): try: url = self.host + '/passport/user/reset' r = requests.post(url, headers=self.headers) return r.json() except requests.exceptions.RequestException as e: log.e( "API", "Something went wrong. Could not update your location:" + str(e), log_to_widget)
def reset_webprofileusername(self, username): ''' Resets the username for the webprofile ''' try: url = self.host + '/profile/username' r = requests.delete(url, headers=self.headers) return r.json() except requests.exceptions.RequestException as e: log.e( "API", "Something went wrong. Could not delete webprofile username:" + str(e), log_to_widget)
def trending_gifs(self, limit=3, log_to_widget=True, thread_update_signal=None): try: url = self.host + '/giphy/trending?limit=%s' % limit r = requests.get(url, headers=self.headers) return r.json() except requests.exceptions.RequestException as e: log.e( "API", "Something went wrong. Could not get the trending gifs:" + str(e), log_to_widget)
def update_tinder_token(self, data): self.config['tinder']['auth_token'] = data log.i("LOGIN_F", "Tinder Token: " + str(self.config['tinder']['auth_token'])) if 'error' in self.config['tinder']['auth_token']: log.e("LOGIN_F", "Error in retreiving token") self.config['tinder']['auth_token'] = '' self.statusBar.showMessage("ERROR") else: self.linedEdit_tinder_token.setText( self.config['tinder']['auth_token']) self.statusBar.showMessage("SUCCESS!: " + self.config['tinder']['auth_token']) QApplication.processEvents()
def gif_query(self, query, limit=3, log_to_widget=True, thread_update_signal=None): try: url = self.host + '/giphy/search?limit=%s&query=%s' % (limit, query) r = requests.get(url, headers=self.headers) return r.json() except requests.exceptions.RequestException as e: log.e("API", "Something went wrong. Could not get your gifs:" + str(e), log_to_widget)
def set_webprofileusername(self, username): ''' Sets the username for the webprofile: https://www.gotinder.com/@YOURUSERNAME ''' try: url = self.host + '/profile/username' r = requests.put(url, headers=self.headers, data=json.dumps({"username": username})) return r.json() except requests.exceptions.RequestException as e: log.e( "API", "Something went wrong. Could not set webprofile username:" + str(e), log_to_widget)
def all_matches(self, amount=60, message=0, page_token=None, log_to_widget=True, thread_update_signal=None): try: url = self.host + '/v2/matches?locale=en&count=' + str( amount) + '&message=' + str(message) + '&is_tinder_u=false' log.d("API", "All matches page: " + str(page_token), log_to_widget) if page_token: url = url + '&page_token=' + page_token r = requests.get(url, headers=self.headers) json = r.json() log.d("API", "All matches keys " + str(json.keys()), log_to_widget) log.d("API", "All matches data " + str(json['data'].keys()), log_to_widget) log.d( "API", "All matches data matches " + str(len(json['data']['matches'])) + " " + str(json['data']['matches'][0].keys()), log_to_widget) log.d("API", "All matches meta " + str(json['meta'].keys()), log_to_widget) log.i( "API", "all_matches: Got response. Status: " + str(json['meta']['status']) + ": " + utils.error_code_to_message[json['meta']['status']], log_to_widget) if 'next_page_token' in json['data']: new_data = self.all_matches(amount, message, json['data']['next_page_token']) for match in new_data['data']['matches']: match[ 'page_token'] = page_token # This will be needed to get messages json['data']['matches'] = json['data']['matches'] + new_data[ 'data']['matches'] self.page_token = json['data']['next_page_token'] elif message <= 0: new_data = self.all_matches(amount, 1, None) json['data']['matches'] = json['data']['matches'] + new_data[ 'data']['matches'] log.i("API", "Total matches " + str(len(json['data']["matches"])), log_to_widget) return json except requests.exceptions.RequestException as e: log.e( "API", "Something went wrong. Could not get your match info:" + str(e), log_to_widget)
def update_fb_token(self, token): print(self.config) try: self.config['facebook']['auth_token'] = token log.d("LOGIN_F", self.config) if 'error' in self.config['facebook']['auth_token']: Exception("Error: " + self.config['facebook']['auth_token']) self.linedEdit_fb_token.setText( self.config['facebook']['auth_token']) self.button_fb_spinner.hideSpinner() except Exception as e: log.e("LOGIN_F", "Exception Getting token: " + str(e)) self.config['facebook']['auth_token'] = "" self.linedEdit_fb_token.setText("ERROR") QApplication.processEvents() self.statusBar.clearMessage()
def load_file(self, fpath): if fpath is not None: try: try: self.jfile = open(fpath) self.jdata = json.load( self.jfile, object_pairs_hook=collections.OrderedDict) except Exception as e: log.i("JSON_VIEWER", "Reading yaml file") self.jfile = open(fpath) self.jdata = yaml.safe_load(self.jfile) return self.jdata except Exception as e: log.e( "JSON_VIEWER", "Error opening json file: " + str(os.path.abspath(fpath)) + " " + str(e))
def send_msg(self, match_id, msg, log_to_widget=True, thread_update_signal=None): try: url = self.host + '/user/matches/%s' % match_id r = requests.post(url, headers=self.headers, data=json.dumps({"message": msg})) return r.json() except requests.exceptions.RequestException as e: log.e( "API", "Something went wrong. Could not send your message:" + str(e), log_to_widget)
def get_meta_v2(self, log_to_widget=True, thread_update_signal=None): ''' Returns meta data on yourself from V2 API. Including the following keys: ['account', 'client_resources', 'plus_screen', 'boost', 'fast_match', 'top_picks', 'paywall', 'merchandising', 'places', 'typing_indicator', 'profile', 'recs'] ''' try: url = self.host + '/v2/meta' r = requests.get(url, headers=self.headers) return r.json() except requests.exceptions.RequestException as e: log.e( "API", "Something went wrong. Could not get your metadata:" + str(e), log_to_widget)
def get_meta(self, log_to_widget=True, thread_update_signal=None): ''' Returns meta data on yourself. Including the following keys: ['globals', 'client_resources', 'versions', 'purchases', 'status', 'groups', 'products', 'rating', 'tutorials', 'travel', 'notifications', 'user'] ''' try: url = self.host + '/meta' r = requests.get(url, headers=self.headers) return r.json() except requests.exceptions.RequestException as e: log.e( "API", "Something went wrong. Could not get your metadata:" + str(e), log_to_widget)
def get_match_info(self, log_to_widget=True, thread_update_signal=None): matches = self.get_updates()['matches'] now = datetime.utcnow() match_info = {} for match in matches[:len(matches)]: try: person = match['person'] person_id = person['_id'] # This ID for looking up person name = person['name'] id = match['id'] msg_count = match['message_count'] photos = self.get_photos(person) bio = "" if 'bio' in person.keys(): bio = person['bio'] gender = person['gender'] avg_succ_rate = self.get_avg_successRate(person) messages = match['messages'] age = self.calculate_age(match['person']['birth_date']) distance = self.get_person(person_id)['results']['distance_mi'] last_activity_date = match['last_activity_date'] match_info[person_id] = { "name": name, "match_id": id, # This ID for messaging "message_count": msg_count, "photos": photos, "bio": bio, "gender": gender, "avg_successRate": avg_succ_rate, "messages": messages, "age": age, "distance": distance, "last_activity_date": last_activity_date, } log.d("API", name + "_" + id) except Exception as ex: template = "An exception of type {0} occurred. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) log.e("API", message) # continue log.i("API", "All data stored in variable: match_info") filename = self.data_folder + 'match_info.json' with open(filename, 'w') as fp: json.dump(match_info, fp) log.i("API", "All data dumped to file: " + str(os.path.abspath(filename))) return match_info
def get_profile(self, doAsync=True, force_update=False): try: with open(self.profile_file, "r") as pf: data = json.load(pf) log.d("APP", "Profile file read: " + str(data)) self.setProfileData(data, download_data=False) except Exception as e: log.e("APP", "No profile found") if self.profile_info is None or force_update: self.get_api_data(doAsync, self.tinder_api.get_self, [], {}, finished_callback=self.setProfileData, callback_kwargs={'download_data': True}, update_callback=self.updateBackgroundTaskInfo, info="Getting profile data", tag="ProfileGetter")