示例#1
0
文件: loginapi.py 项目: yqingp/Zeus
    def feed_timeline(self):

        body = dict()
        body["feed_view_info"] = '[]'  # TODO
        body["phone_id"] = self.device.get('phone_id')
        body["reason"] = "cold_start_fetch"
        body["battery_level"] = random.randint(40, 100)
        # body['last_unseen_ad_id'] = '' # TODO
        body["timezone_offset"] = '2600'  # self.geo.timezone_offset
        body["_csrftoken"] = self.session.get_csrftoken()
        body["device_id"] = self.device.get('android_device_id')
        body["request_id"] = Signature.generate_UUID(True),
        body["is_pull_to_refresh"] = '0'
        body["_uuid"] = self.device.get('uuid')
        body["is_charging"] = '0'
        body["will_sound_on"] = '0'
        body["session_id"] = Signature.generate_UUID(True)
        body["bloks_versioning_id"] = Constants.X_BLOKS_VERSION_ID

        self.session.set_headers(is_post=True, prefix=True, gzip=True)

        return self.request.send_request(endpoint=Constants.API_URL1 +
                                         'feed/timeline/',
                                         post=body,
                                         with_signature=False,
                                         account=self.account,
                                         device=self.device,
                                         session=self.session)
示例#2
0
文件: loginapi.py 项目: yqingp/Zeus
    def open_app(self):
        # Open the instagram application and go to main page
        # This function is called in photo upload function in 'photo' module
        print(
            "Refresh the application session [Close and reopen your instagram app]"
        )
        x_pigeon = Signature.generate_UUID(True)
        try:
            self.device.update({'x_pigeon': x_pigeon})
        except Exception as e:
            print(e)
        # If this endpoint response is not ok, then account may be blocked
        # so get the message and update account status
        if not self.feed_reels_tray():
            message = 'message'
            try:
                message = self.request.last_json['message']
            except Exception as e:
                print(e)
            update_account_status(self.account.get('username'), message)
            print(colored('THIS ACCOUNT IS PROBABLY BLOCKED', 'red'))
            return False

        self.feed_timeline()
        self.igtv_browse_feed()
        self.launcher_sync(pre_login=False, id_is_uuid=True)
        self.qe_sync(pre_login=False,
                     experiments=Constants.EXPERIMENTS,
                     id_is_uuid=True)
        self.launcher_sync(pre_login=False)
        self.qe_sync(pre_login=False, experiments=Constants.EXPERIMENTS2)
        self.media_blocked()
        self.qp_batch_fetch(Constants.SURFACES_TO_TRIGGERS1,
                            Constants.SURFACES_TO_QUERIES1)
        self.banyan_banyan()
        self.branded_content()
        self.news_inbox()
        self.arlink_download_info()
        # self.process_contact_point_signals() # TODO 429 response
        self.business_eligibility()
        self.multiple_accounts()
        self.scores_bootstrap()
        self.banyan_banyan()
        self.status()
        self.users_info(userid=self.account.get('user_id'))
        self.get_presence()
        self.discover()
        self.direct_v2_inbox()
        self.loom_fetch()
        self.notifications_badge()

        # Save your application session information
        self.save_login_state()
        # Update the x_pigeon of the application so that
        # the same x_pigeon can be used in other classes
        update_x_pigeon(self.account.get('username'), x_pigeon)

        return True
示例#3
0
文件: photo.py 项目: yqingp/Zeus
 def location_search(self):
     param = dict()
     param['latitude'] = self.geo.latitude
     param['rankToken'] = Signature.generate_UUID(True)  # TODO
     param['longitude'] = self.geo.longitude
     self.session.set_headers(auth=True)
     return self.request.send_request(endpoint=Constants.API_URL1 + "location_search/",
                                      params=param,
                                      session=self.session
                                      )
示例#4
0
 def __init__(self, username=None, link=None, proxy=None):
     self.user = User(username=username)
     self.account = self.user.account
     self.device = self.user.device
     self.session = Session(username=username, proxy=proxy)
     self.request = Request()
     self.client_username = link.split('?')[0].split('/')[3]
     self.client_id = None
     self.x_pigeon = Signature.generate_UUID(True)
     self.geo = Geo(proxy=proxy)
示例#5
0
文件: device.py 项目: yqingp/Zeus
 def __init__(self):
     self.uuid = Signature.generate_UUID(True)
     self.phone_id = Signature.generate_UUID(True)
     self.x_pigeon = Signature.generate_UUID(True)
     self.android_device_id = Signature.generate_device_id(self.phone_id)
     self.jazoest = Signature.generate_jazoest(self.phone_id)
     self.waterfall_id = Signature.generate_UUID(True)
     self.advertising_id = Signature.generate_UUID(True)
     self.attribution_id = Signature.generate_UUID(True)
示例#6
0
文件: loginapi.py 项目: yqingp/Zeus
    def login_flow(self, just_logged_in, app_refresh_interval=3):

        # If user is just logged in then make sure that all login API flow is performed successfully
        if just_logged_in:
            self.multiple_accounts()
            self.launcher_sync(pre_login=True)
            self.qe_sync(pre_login=False)
            self.feed_timeline()
            self.igtv_browse_feed()
            self.feed_reels_tray()
            self.launcher_sync(pre_login=True, login_configs=True)
            self.feed_reels_media()
            self.news_inbox()
            #        self.business_eligibility()
            self.log_attribution()
            self.loom_fetch()
            self.scores_bootstrap()
            self.users_info(self.account.get('user_id'))
            self.linked_accounts()
            self.write_supported_capabilities()
            self.media_blocked()
            self.store_client_push_permissions()
            self.qp_get_cooldowns()
            self.discover()
            self.qp_batch_fetch(Constants.SURFACES_TO_TRIGGERS1,
                                Constants.SURFACES_TO_QUERIES1)
            #           self.process_contact_point_signals()
            self.arlink_download_info()
            self.banyan_banyan()
            self.get_presence()
            self.direct_v2_inbox()
            self.notifications_badge()
            self.facebook_ota()

            self.save_login_state()
            print("You logged in successfully !")

        else:
            print("YOU ALREADY LOGGED IN")
            # GET USER'S LAST LOGIN TIME
            last_login_time = self.account.get('last_login')

            # CHECK USER'S SESSION IS EXPIRED
            is_session_expired = (last_login_time is None) or (
                time.time() - last_login_time) > app_refresh_interval
            if is_session_expired:

                # update app's session id when user closes and re opens the app
                print(
                    "Refresh the application session [Close and reopen your instagram app]"
                )
                x_pigeon = Signature.generate_UUID(True)
                try:
                    self.device.update({'x_pigeon': x_pigeon})
                except Exception as e:
                    print(e)
                # If this endpoint response is not ok, then account may be blocked
                # so get the message and update account status
                if not self.feed_reels_tray():
                    message = 'message'
                    try:
                        message = self.request.last_json['message']
                    except Exception as e:
                        print(e)
                    update_account_status(self.account.get('username'),
                                          message)
                    print(colored('THIS ACCOUNT IS PROBABLY BLOCKED', 'red'))
                    return False

                self.feed_timeline()
                self.igtv_browse_feed()
                self.launcher_sync(pre_login=False, id_is_uuid=True)
                self.qe_sync(pre_login=False,
                             experiments=Constants.EXPERIMENTS,
                             id_is_uuid=True)
                self.launcher_sync(pre_login=False)
                self.qe_sync(pre_login=False,
                             experiments=Constants.EXPERIMENTS2)
                self.media_blocked()
                self.qp_batch_fetch(Constants.SURFACES_TO_TRIGGERS1,
                                    Constants.SURFACES_TO_QUERIES1)
                self.banyan_banyan()
                self.branded_content()
                self.news_inbox()
                self.business_eligibility()
                self.multiple_accounts()
                self.scores_bootstrap()
                self.banyan_banyan()
                self.status()
                self.users_info(userid=self.account.get('user_id'))
                self.get_presence()
                self.discover()
                self.direct_v2_inbox()
                self.loom_fetch()
                self.notifications_badge()

                # Save your application session information
                self.save_login_state()
                # Update the x_pigeon of the application so that
                # the same x_pigeon can be used in other classes
                update_x_pigeon(self.account.get('username'), x_pigeon)

                return True

            else:
                print("Your app is open")
                return True
示例#7
0
文件: session.py 项目: yqingp/Zeus
    def set_headers(self,
                    prefix=False,
                    x_device=False,
                    prefetch_request=False,
                    is_post=False,
                    cookie=True,
                    auth=False,
                    mid=False,
                    gzip=False,
                    retry_context=False,
                    host='i.instagram.com'):
        self.headers = {}
        if prefix:
            self.headers['X-Ads-Opt-Out'] = '0'
            self.headers['X-Attribution-ID'] = Signature.generate_UUID(
                True)  # self.device.get('attribution_id')
            self.headers['X-Google-AD-ID'] = self.device.get('advertising_id')
            self.headers['X-DEVICE-ID'] = self.device.get('uuid')
            self.headers['X-FB'] = '1'
            self.headers['X-CM-Bandwidth-KBPS'] = str(
                round(random.uniform(2000, 5000), 3))  # TODO
            self.headers['X-CM-Latency'] = str(round(random.uniform(8, 20),
                                                     3))  # TODO
        if x_device and not prefix:
            self.headers['X-DEVICE-ID'] = self.device.get('uuid')
        self.headers['X-IG-App-Locale'] = 'en_US'
        self.headers['X-IG-Device-Locale'] = 'en_US'
        self.headers['X-IG-Mapped-Locale'] = 'en_US'
        self.headers['X-Pigeon-Session-Id'] = self.device.get('x_pigeon')
        self.headers['X-Pigeon-Rawclienttime'] = str(round(time.time(), 3))
        self.headers['X-IG-Connection-Speed'] = '-1kbps'
        self.headers['X-IG-Bandwidth-Speed-KBPS'] = str(
            round(random.uniform(2000, 5000), 3))
        self.headers['X-IG-Bandwidth-TotalBytes-B'] = str(
            random.randint(500000, 900000))
        self.headers['X-IG-Bandwidth-TotalTime-MS'] = str(
            random.randint(200, 500))
        if prefetch_request:
            self.headers['X-IG-Prefetch-Request'] = 'foreground'
        self.headers['X-IG-App-Startup-Country'] = 'US'
        self.headers['X-Bloks-Version-Id'] = Constants.X_BLOKS_VERSION_ID
        self.headers['X-IG-WWW-Claim'] = Constants.X_IG_WWW_CLAIM
        self.headers['X-Bloks-Is-Layout-RTL'] = 'false'
        self.headers['X-Bloks-Enable-RenderCore'] = 'false'
        self.headers['X-IG-Device-ID'] = self.device.get('uuid')
        self.headers['X-IG-Android-ID'] = self.device.get('android_device_id')
        if retry_context:
            self.headers['retry_context'] = json.dumps(
                {
                    "num_reupload": 0,
                    "num_step_auto_retry": 0,
                    "num_step_manual_retry": 0
                },
                separators=(',', ':'))
        self.headers['X-IG-Connection-Type'] = 'WIFI'
        self.headers['X-IG-Capabilities'] = Constants.X_IG_CAPABILITIES
        self.headers['X-IG-App-ID'] = Constants.X_IG_APP_ID
        self.headers['User-Agent'] = self.device.get('user_agent')
        self.headers['Accept-Language'] = 'en-US'
        if cookie:
            self.headers['Cookie'] = self.get_cookie_string()
        if auth:
            self.headers[
                'Authorization'] = 'Bearer IGT:2:' + self.get_authorization_bearer(
                )
            self.headers['X-MID'] = self.get_mid()
        if is_post:
            self.headers[
                'Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
        if gzip:
            self.headers['Content-Encoding'] = 'gzip'
        self.headers['Accept-Encoding'] = 'gzip, deflate'

        self.headers['Host'] = host
        self.headers['X-FB-HTTP-Engine'] = 'Liger'
        self.headers['Connection'] = 'close'
示例#8
0
文件: photo.py 项目: yqingp/Zeus
    def upload_post_photo(self, path_to_photo):
        # Open the app and get timeline page before post.
        # If timeline does not respond, update the account status
        if not self.login.open_app():
            return

        time.sleep(random.randint(3, 10))

        self.reload_user(self.username) # TODO

        time.sleep(random.randint(10, 20))
        self.location_search()
        self.qp_batch_fetch()

        time.sleep(random.randint(5, 10))
        upload_id = str(int(time.time() * 1000))
        some_number = str(random.randint(-2 ** 10, 2 ** 10))
        waterfall_id = Signature.generate_UUID(True)

        def upload():
            response = self.upload_photo(path_to_photo, upload_id, some_number, waterfall_id, force_resize=True,
                                                post=True)
            if not response:
                return upload()
            return True

        upload()

        self.session.set_headers(retry_context=True ,is_post=True, auth=True)
        width, height = self.get_image_size(path_to_photo)

        data = dict()
        data['timezone_offset'] = self.geo.timezone_offset
        data['_csrftoken'] = self.session.get_csrftoken()
        data['media_folder'] = 'Download'
        data['source_type'] = '4'
        data['_uid'] = self.account.get('user_id')
        data['device_id'] = self.device.get('android_device_id')
        data['_uuid'] = self.device.get('uuid')
        data['creation_logger_session_id'] = Signature.generate_UUID(True)
        # data['location'] = json.dumps({}, separators=(",",":")) # TODO
        # data['suggested_venue_position'] = '-1' # TODO
        data['caption'] = ''
        data['upload_id'] = upload_id
        data['device'] = self.get_device_details()
        data['edits'] = {
            "crop_original_size": [width * 1.0, height * 1.0],
            "crop_center": [0.0, -0.0], # TODO
            "crop_zoom": 1.0,
        }
        data['extra'] = {"source_width": width, "source_height": height}
        # data['is_suggested_venue'] = 'False' # TODO

        try:
            is_photo_posted = self.request.send_request(endpoint=Constants.API_URL1 + 'media/configure/',
                                                        post=data,
                                                        session=self.session
                                                        )

            if is_photo_posted:
                print(colored('*** PHOTO POSTED SUCCESSFULLY ***', 'green', attrs=['bold']))
            else:
                print(colored('*** POSTING PHOTO ATTEMPT IS FAILED ***', 'red', attrs=['bold']))
        except:
            print(colored('SOMETHING WENT WRONG WHEN UPLOADING PROFILE PHOTO', 'red', attrs=['bold']))
        update_cookie(self.account.get('username'), self.request.cookie)
示例#9
0
文件: photo.py 项目: yqingp/Zeus
    def set_profile_photo(self, path_to_photo):

        # OPEN THE APP OR LOGIN AGAIN IN ORDER TO CHANGE PROFILE PHOTO ( We use 'loginapi' module to do this )
        self.login.login(False)

        time.sleep(random.randint(4, 10))  # TODO

        self.reload_user(self.username)

        self.feed_user_story(1)
        self.feed_user_story(2)
        self.profile_su_badge()
        self.users_info(self.account.get('user_id'))
        self.qp_batch_fetch()
        self.highlights()
        self.profile_archive_badge()
        self.get_invite_suggestions()

        time.sleep(random.randint(5, 15))
        self.location_search() # TODO

        upload_id = str(int(time.time() * 1000))
        some_number = str(random.randint(-2 ** 10, 2 ** 10))
        waterfall_id = Signature.generate_UUID(True)

        time.sleep(random.randint(10, 15))
        try:
            if not self.get_upload_photo(upload_id, some_number, waterfall_id):
                raise Exception
        except Exception as e:
            print(e)
            print('MISSING OR INCOMPATIBLE PHOTO')

        try:
            if not self.upload_photo(path_to_photo, upload_id, some_number, waterfall_id, force_resize=True):
                raise Exception
        except Exception as e:
            print(e)
            print('MISSING OR INCOMPATIBLE PHOTO')
            raise

        data = dict()
        data['_csrftoken'] = self.session.get_csrftoken()
        data['_uuid'] = self.device.get('uuid')
        data['use_fbuploader'] = 'true'
        data['upload_id'] = upload_id  # TODO

        self.session.set_headers(is_post=True)

        is_photo_uploaded = self.request.send_request(endpoint=Constants.API_URL1 + 'accounts/change_profile_picture/',
                                                      post=data,
                                                      with_signature=False,
                                                      session=self.session)

        if is_photo_uploaded:
            print(colored('*** YOUR PROFILE PICTURE IS CHANGED ***', 'green', attrs=['bold']))
        else:
            print(colored('*** CHANGING PROFILE PICTURE ATTEMPT IS FAILED ***', 'red', attrs=['bold']))

        try:
            update_cookie(self.account.get('username'), self.request.cookie)
        except:
            pass