本文整理汇总了Python中session.Session.logout方法的典型用法代码示例。如果您正苦于以下问题:Python Session.logout方法的具体用法?Python Session.logout怎么用?Python Session.logout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类session.Session
的用法示例。
在下文中一共展示了Session.logout方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: logout_slave
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import logout [as 别名]
def logout_slave(self):
if Session.logout(self._slave_session, True):
self._slave_session = None
return True
return False
示例2: InstaBot
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import logout [as 别名]
class InstaBot(object):
def __init__(self, config_path, log_file_path=None):
start_time = datetime.datetime.now()
config = yaml.safe_load(open(config_path, "r"))
username, password, tags, total_likes, likes_per_user = (config['CREDENTIALS']['USERNAME'], config['CREDENTIALS']['PASSWORD'],
config['TAGS'], config['TOTAL_LIKES'], config['LIKES_PER_USER'])
self.logger = Logger(username, log_file_path)
self.logger.log('InstaBot v0.1 started at: %s' % (start_time.strftime("%d.%m.%Y %H:%M")))
self.total_likes = total_likes + self.iround(min(total_likes/2, max(-total_likes/2, random.gauss(0, 100)))) # gaussian distribution: mu = 0, sig = 100, round to nearest int
self.logger.log('InstaBot v0.1 will like ' + str(self.total_likes) + ' photos in total')
self.likes_per_user = likes_per_user
self.liked_photos = set()
self.session = Session(username, password, self.logger)
# random.shuffle(tags)
self.run(username, password, tags)
self.session.logout()
end_time = datetime.datetime.now()
self.logger.log('InstaBot v0.1 stopped at: %s' % (end_time.strftime("%d.%m.%Y %H:%M")))
self.logger.log('InstaBot v0.1 took ' + str(end_time-start_time) + ' in total')
def get_html(self, url):
time_between_requests = random.randint(7,12)
self.logger.log('Fetching ' + url)
response = requests.get(url, verify=False, timeout=WAIT_SERVER_RESPONSE_TIME)
html = response.text
time.sleep(time_between_requests)
return html
def get_data_from_html(self, html):
try:
finder_start = '<script type="text/javascript">window._sharedData = '
finder_end = ';</script>'
data_start = html.find(finder_start)
data_end = html.find(finder_end, data_start+1)
json_str = html[data_start+len(finder_start):data_end]
data = json.loads(json_str)
return data
except json.decoder.JSONDecodeError as e:
self.logger.log('Error parsing json string: ' + str(e))
def get_recent_tag_photos(self, tag):
url = URL.tag + tag
photos = list()
min_likes = 5
max_likes = 500
min_comments = 1
max_comments = 50
try:
html = self.get_html(url)
data = self.get_data_from_html(html)
# get data from recent posts only
photos_json = list(data['entry_data']['TagPage'][0]['tag']['media']['nodes'])
for photo_json in photos_json:
photo_id = photo_json['code']
likes = photo_json['likes']['count']
comments = photo_json['comments']['count']
if photo_id not in self.liked_photos and ((likes >= min_likes and likes <= max_likes) or (comments >= min_comments and comments <= max_comments)):
photos.append(photo_id)
if len(photos) == 10:
break
# fill up rest of photos list with top posts, until list has 10 potential people to be liked
if len(photos) < 10:
photos_json = list(data['entry_data']['TagPage'][0]['tag']['top_posts']['nodes'])
for photo_json in photos_json:
photo_id = photo_json['code']
likes = photo_json['likes']['count']
comments = photo_json['comments']['count']
if photo_id not in self.liked_photos and ((likes >= min_likes and likes <= max_likes) or (comments >= min_comments and comments <= max_comments)):
photos.append(photo_id)
if len(photos) == 10:
break
except (KeyError, IndexError, TypeError) as e:
self.logger.log('Error parsing url: ' + url + ' - ' + str(e))
time.sleep(10)
return photos
def get_photo_owner(self, photo_id):
try:
photo_url = URL.photo + photo_id
html = self.get_html(photo_url)
data = self.get_data_from_html(html)
# owner_name = data['entry_data']['PostPage'][0]['media']['owner']['username'] # deprecated
owner_name = data['entry_data']['PostPage'][0]['graphql']['shortcode_media']['owner']['username'] # new format
return owner_name
except (KeyError, IndexError, TypeError) as e:
self.logger.log('Error parsing url: ' + photo_url + ' - ' + str(e))
time.sleep(10)
return None
# get owner recent photos only if he/she meets requirements
def get_owner_recent_photos(self, owner_name):
photos = list()
min_followed_by = 200
max_followed_by = 2000
min_follows = 200
max_follows = 7500 # instagram limit
min_follow_ratio = 0.05
max_follow_ratio = 5.0
owner_url = URL.root + owner_name
#.........这里部分代码省略.........
示例3: logout
# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import logout [as 别名]
def logout(self):
if Session.logout(self._session, False):
self._session = None
return True
return False