Exemplo n.º 1
0
 def download_people_data_api(self,
                              data_list,
                              folder_path,
                              photos,
                              insta,
                              messages,
                              rename_images,
                              amount,
                              force_overwrite=False,
                              log_to_widget=True,
                              thread_update_signal=None):
     downloaded_data = []
     if not isinstance(data_list, list):
         data_list = [data_list]
     total = len(data_list)
     if amount > 0:
         total = min(total, amount)
     for i in range(total):
         if thread_update_signal is not None:
             thread_update_signal.emit("Downloading " + str(folder_path) +
                                       ": " + str(i + 1) + "/" + str(total))
         log.i("API", "Downloading " + str(i + 1) + "/" + str(total),
               log_to_widget)
         updated_data = self.download_person_data(data_list[i], folder_path,
                                                  photos, insta, messages,
                                                  rename_images,
                                                  force_overwrite,
                                                  log_to_widget,
                                                  thread_update_signal)
         downloaded_data.append(updated_data)
         log.i("API", "Data Downloaded!", log_to_widget)
     return downloaded_data
Exemplo n.º 2
0
 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")
Exemplo n.º 3
0
 def update_status_bar(self):
     if self.logged_in:
         log.i("APP", "Login verified!")
         self.window.statusBar.showMessage("Login verified!")
         self.window.setWindowTitle("TinderAI (Online)")
     else:
         log.i("APP", "Login FAILED!")
         self.window.statusBar.showMessage("Login FAILED!")
         self.window.setWindowTitle("TinderAI (OFFLINE)")
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
 def get_user_id(self, doAsync=True):
     print(self.config)
     log.i("LOGIN_F", "Retreiving Facebook user id...")
     self.statusBar.showMessage("Retreiving user id from FB...")
     self.app.get_api_data(doAsync,
                           self.app.tinder_api.get_fb_user_id,
                           [self.config['facebook']['auth_token']], {},
                           finished_callback=self.update_user_id,
                           info="Getting FB auth token",
                           tag="FBUserIdThread")
Exemplo n.º 6
0
 def get_tinder_access_token(self, doAsync=True):
     log.i("LOGIN_F", "Retreiving token from Tinder...")
     self.statusBar.showMessage("Retreiving token from Tinder...")
     self.app.get_api_data(doAsync,
                           self.app.tinder_api.get_auth_token, [
                               self.config['facebook']['auth_token'],
                               self.config['facebook']['user_id']
                           ], {},
                           finished_callback=self.update_tinder_token,
                           info="Getting Tinder auth token",
                           tag="TinderTokenThread")
Exemplo n.º 7
0
 def verify_login(self, doAsync, callback):
     log.i("APP", "Config File: " + str(os.path.abspath(self.config_file)))
     log.i("APP", "Verify login: "******"Verifying login",
                       tag="LoginVerifier")
Exemplo n.º 8
0
 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))
Exemplo n.º 9
0
 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))
Exemplo n.º 10
0
 def how_long_has_it_been(self,
                          log_to_widget=True,
                          thread_update_signal=None):
     global match_info
     now = datetime.utcnow()
     times = {}
     for person in match_info:
         name = match_info[person]['name']
         ping_time = match_info[person]['last_activity_date']
         since = self.get_last_activity_date(now, ping_time)
         times[name] = since
         log.i("API", name, "----->", since)
     return times
Exemplo n.º 11
0
 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()
Exemplo n.º 12
0
 def update_user_id(self, data):
     self.config['facebook']['user_id'] = data
     if 'error' in self.config['facebook']['user_id']:
         log.i("LOGIN_F", "Error retreiving user id")
         self.linedEdit_fb_user_id.setText("ERROR!")
         self.config['facebook']['user_id'] = ''
     else:
         log.i(
             "LOGIN_F",
             "User id received: " + str(self.config['facebook']['user_id']))
         self.linedEdit_fb_user_id.setText(
             self.config['facebook']['user_id'])
     QApplication.processEvents()
     self.statusBar.clearMessage()
Exemplo n.º 13
0
 def get_fb_access_token(self, doAsync=True):
     print(self.config)
     log.i("LOGIN_F", "Retreiving token from FB...")
     self.statusBar.showMessage("Retreiving token from FB...")
     self.config['facebook']['email'] = self.lineEdit_username.text()
     self.config['facebook']['password'] = self.lineEdit_password.text()
     self.app.get_api_data(doAsync,
                           self.app.tinder_api.get_fb_access_token, [
                               self.config['facebook']['email'],
                               self.config['facebook']['password']
                           ], {},
                           finished_callback=self.update_fb_token,
                           info="Getting FB auth token",
                           tag="FbTokenThread")
Exemplo n.º 14
0
    def download_person_data(self,
                             data,
                             base_folder,
                             photos,
                             insta,
                             messages,
                             rename_images,
                             force_overwrite=False,
                             log_to_widget=True,
                             thread_update_signal=None):
        person_data, type = self.get_person_data(data)
        id = person_data['_id']
        name = person_data['name']
        path = base_folder + "/" + str(name) + "_" + str(id) + "/"
        person_data['path'] = str(os.path.abspath(path))
        log.i(
            "API", "Downloading " + type + ": " + name + " " + id + " to: " +
            str(person_data['path']), log_to_widget)
        if os.path.exists(path):
            log.d("API", "Person path already exists: " + person_data['path'],
                  log_to_widget)
        else:
            os.makedirs(path)
            log.d("API", "Person path created: " + person_data['path'],
                  log_to_widget)
        person_data['local_path'] = str(os.path.abspath(path))

        if insta and 'instagarm' in person_data:
            self.download_instagram_photos(person_data['instagram'], path,
                                           rename_images, force_overwrite,
                                           log_to_widget, thread_update_signal)

        if photos and 'photos' in person_data:
            self.download_photos(person_data['photos'], path, rename_images,
                                 force_overwrite, log_to_widget,
                                 thread_update_signal)

        if messages and 'match' in type:
            data['messages'] = self.download_messages(data, log_to_widget,
                                                      thread_update_signal)

        data['AI_Dating_metadata'] = {}
        data['AI_Dating_metadata']['last_updated_datetime'] = str(
            datetime.now().strftime("%d-%b-%Y %H:%M:%S"))
        data['AI_Dating_metadata']['last_updated_timestamp'] = str(
            datetime.utcnow())

        self.write_data_to_file(data, path, log_to_widget,
                                thread_update_signal)
        return data
Exemplo n.º 15
0
 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)
Exemplo n.º 16
0
 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))
Exemplo n.º 17
0
 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
Exemplo n.º 18
0
 def get_recommendations(self,
                         log_to_widget=True,
                         thread_update_signal=None):
     '''
     Returns a list of users that you can swipe on
     '''
     try:
         r = requests.get('https://api.gotinder.com/user/recs',
                          headers=self.headers)
         json = r.json()
         log.i(
             "API", "get_recommendations: Got response. Status: " +
             str(json['status']) + ": " +
             utils.error_code_to_message[json['status']], log_to_widget)
         return json
     except requests.exceptions.RequestException as e:
         log.e("API",
               "Something went wrong with getting recomendations:" + str(e),
               log_to_widget)
Exemplo n.º 19
0
 def read_data(self,
               file_path,
               log_to_widget=True,
               thread_update_signal=None):
     try:
         with open(file_path, "r") as f:
             try:
                 data = json.load(f)
             except Exception as e:
                 try:
                     data = yaml.safe_load(f)
                 except Exception as e:
                     return None
             log.i("API", "Data read from file: " + str(file_path),
                   log_to_widget)
             return data
     except Exception as e:
         log.e(
             "API", "Exception reading data from file : " +
             str(os.path.abspath(file_path)) + ", Exc: " + str(e),
             log_to_widget)
         return None
Exemplo n.º 20
0
 def download_file(self,
                   url,
                   base_path,
                   rename,
                   index,
                   postfix="",
                   force_overwrite=False,
                   log_to_widget=True,
                   thread_update_signal=None):
     try:
         file_name = str(index) + postfix + ".jpg"
         if not rename:
             file_name = (url.split("/")[-1] + '.jpg').split('?')[0]
         full_filename = base_path + file_name
         if not os.path.exists(base_path):
             os.makedirs(base_path)
             log.d("API", "File path created: " + base_path, log_to_widget)
         if not os.path.exists(full_filename) or force_overwrite:
             self.browser.open(url)
             with open(full_filename, "wb") as image_file:
                 image_file.write(self.browser.response.content)
                 if force_overwrite:
                     log.d("API", "Forcing Re-Download: " + full_filename,
                           log_to_widget)
                 else:
                     log.i("API", "Downloading: " + full_filename,
                           log_to_widget)
                 return full_filename, False
         else:
             log.d(
                 "API",
                 "File already downloaded (force_overwrite=False): " +
                 full_filename, log_to_widget)
             return full_filename, True
     except Exception as e:
         log.e("API", "EXCEPTION!: " + str(e), log_to_widget)
         return None, False
Exemplo n.º 21
0
 def get_auth_token(self,
                    fb_auth_token,
                    fb_user_id,
                    log_to_widget=True,
                    thread_update_signal=None):
     log.d("API", "get_auth_token: " + fb_auth_token + "\t" + fb_user_id,
           log_to_widget)
     if "error" in fb_auth_token:
         return {"error": "could not retrieve fb_auth_token"}
     if "error" in fb_user_id:
         return {"error": "could not retrieve fb_user_id"}
     url = self.host + '/v2/auth/login/facebook'
     req = requests.post(url,
                         headers=self.headers,
                         data=json.dumps({
                             'token': fb_auth_token,
                             'facebook_id': fb_user_id
                         }))
     try:
         log.d("API", "Sending JSON request", log_to_widget)
         json_request = req.json()
         log.i("API",
               "Token JSON status: " + str(json_request['meta']['status']),
               log_to_widget)
         tinder_auth_token = json_request["data"]["api_token"]
         self.headers.update({"X-Auth-Token": tinder_auth_token})
         self.get_headers.update({"X-Auth-Token": tinder_auth_token})
         self.get_message_headers.update(
             {"X-Auth-Token": tinder_auth_token})
         log.s("API", "You have been successfully authorized!")
         return tinder_auth_token
     except Exception as e:
         log.e("API", "Error getting Tinder Token " + str(e), log_to_widget)
         return {
             "error":
             "Something went wrong. Sorry, but we could not authorize you."
         }
Exemplo n.º 22
0
    def reload_data_from_disk(self,
                              folder_path,
                              merged_filename,
                              photos,
                              insta,
                              messages,
                              force_overwrite=False,
                              log_to_widget=True,
                              thread_update_signal=None):
        list = []
        try:
            for subdir, dirs, files in os.walk(folder_path):
                total_dirs = len(dirs)
                for i in range(len(dirs)):
                    data_path = os.path.join(subdir, dirs[i]) + "/"
                    data_file_path = data_path + "data.yaml"
                    try:
                        if os.path.exists(data_file_path):
                            with open(data_file_path) as yf:
                                data = yaml.safe_load(yf)
                                person_data, type = self.get_person_data(data)
                                person_data['path'] = os.path.abspath(
                                    data_path
                                )  # Updating the data path just in case
                                if photos and 'photos' in person_data:
                                    self.download_photos(
                                        person_data['photos'],
                                        data_path,
                                        True,
                                        force_overwrite,
                                        log_to_widget=log_to_widget)

                                if insta and 'instagram' in person_data and 'photos' in person_data[
                                        'instagram']:
                                    self.download_instagram_photos(
                                        person_data['instagram'],
                                        data_path,
                                        True,
                                        force_overwrite,
                                        log_to_widget=log_to_widget)
                                if messages and 'match' in type:
                                    data['messages'] = self.download_messages(
                                        data, log_to_widget)
                                log.d("API", "Updating " + type + " data file",
                                      log_to_widget)

                                data['AI_Dating_metadata'] = {}
                                data['AI_Dating_metadata'][
                                    'last_updated_datetime'] = str(
                                        datetime.now().strftime(
                                            "%d-%b-%Y %H:%M:%S"))
                                data['AI_Dating_metadata'][
                                    'last_updated_timestamp'] = str(
                                        datetime.utcnow())

                                self.write_data_to_file(
                                    data, data_path, log_to_widget,
                                    thread_update_signal)
                                log.d("API", "Updated", log_to_widget)
                                list.append(data)
                            log.i(
                                "API",
                                str(i + 1) + "/" + str(total_dirs) + " - " +
                                str(dirs[i]) + " " + person_data['name'],
                                log_to_widget)
                        else:
                            log.i(
                                "API",
                                str(i + 1) + "/" + str(total_dirs) + " - " +
                                str(dirs[i]) + " SKIPPED", log_to_widget)
                    except Exception as e:
                        log.e("API", "Exception reloading data " + str(e),
                              log_to_widget)
                    if thread_update_signal is not None:
                        thread_update_signal.emit(
                            str(folder_path) + "\t" + str(i + 1) + "/" +
                            str(total_dirs))
                break
        except Exception as e:
            log.e("API", "Exception in reloading from disk: " + str(e),
                  log_to_widget)
        try:
            with open(merged_filename, "w+") as f:
                json.dump(list, f)
        except Exception as e:
            log.e(
                "API", "Could not save merged file " + merged_filename + ": " +
                str(e), log_to_widget)
        return list