def get_tweets(user, pages=<NUM_LIT>):
url = f'<STR_LIT>'<EOL>headers = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': f'<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT:yes>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>'<EOL>}<EOL>def gen_tweets(pages):<EOL><INDENT>r = session.get(url, headers=headers)<EOL>while pages > <NUM_LIT:0>:<EOL><INDENT>try:<EOL><INDENT>html = HTML(html=r.json()['<STR_LIT>'],<EOL>url='<STR_LIT>', default_encoding='<STR_LIT:utf-8>')<EOL><DEDENT>except KeyError:<EOL><INDENT>raise ValueError(<EOL>f'<STR_LIT>')<EOL><DEDENT>comma = "<STR_LIT:U+002C>"<EOL>dot = "<STR_LIT:.>"<EOL>tweets = []<EOL>for tweet in html.find('<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>text = tweet.find('<STR_LIT>')[<NUM_LIT:0>].full_text<EOL><DEDENT>except IndexError:  <EOL><INDENT>continue<EOL><DEDENT>tweet_id = tweet.find('<STR_LIT>')[<NUM_LIT:0>].attrs['<STR_LIT>']<EOL>time = datetime.fromtimestamp(int(tweet.find('<STR_LIT>')[<NUM_LIT:0>].attrs['<STR_LIT>']) / <NUM_LIT>)<EOL>interactions = [<EOL>x.text<EOL>for x in tweet.find('<STR_LIT>')<EOL>]<EOL>replies = int(<EOL>interactions[<NUM_LIT:0>].split('<STR_LIT:U+0020>')[<NUM_LIT:0>].replace(comma, '<STR_LIT>').replace(dot, '<STR_LIT>')<EOL>or interactions[<NUM_LIT:3>]<EOL>)<EOL>retweets = int(<EOL>interactions[<NUM_LIT:1>].split('<STR_LIT:U+0020>')[<NUM_LIT:0>].replace(comma, '<STR_LIT>').replace(dot, '<STR_LIT>')<EOL>or interactions[<NUM_LIT:4>]<EOL>or interactions[<NUM_LIT:5>]<EOL>)<EOL>likes = int(<EOL>interactions[<NUM_LIT:2>].split('<STR_LIT:U+0020>')[<NUM_LIT:0>].replace(comma, '<STR_LIT>').replace(dot, '<STR_LIT>')<EOL>or interactions[<NUM_LIT:6>]<EOL>or interactions[<NUM_LIT:7>]<EOL>)<EOL>hashtags = [<EOL>hashtag_node.full_text<EOL>for hashtag_node in tweet.find('<STR_LIT>')<EOL>]<EOL>urls = [<EOL>url_node.attrs['<STR_LIT>']<EOL>for url_node in tweet.find('<STR_LIT>')<EOL>]<EOL>photos = [<EOL>photo_node.attrs['<STR_LIT>']<EOL>for photo_node in tweet.find('<STR_LIT>')<EOL>]<EOL>videos = []<EOL>video_nodes = tweet.find("<STR_LIT>")<EOL>for node in video_nodes:<EOL><INDENT>styles = node.attrs['<STR_LIT>'].split()<EOL>for style in styles:<EOL><INDENT>if style.startswith('<STR_LIT>'):<EOL><INDENT>tmp = style.split('<STR_LIT:/>')[-<NUM_LIT:1>]<EOL>video_id = tmp[:tmp.index('<STR_LIT>')]<EOL>videos.append({'<STR_LIT:id>': video_id})<EOL><DEDENT><DEDENT><DEDENT>tweets.append({<EOL>'<STR_LIT>': tweet_id,<EOL>'<STR_LIT:time>': time,<EOL>'<STR_LIT:text>': text,<EOL>'<STR_LIT>': replies,<EOL>'<STR_LIT>': retweets,<EOL>'<STR_LIT>': likes,<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': hashtags, '<STR_LIT>': urls,<EOL>'<STR_LIT>': photos, '<STR_LIT>': videos<EOL>}<EOL>})<EOL><DEDENT>last_tweet = html.find('<STR_LIT>')[-<NUM_LIT:1>].attrs['<STR_LIT>']<EOL>for tweet in tweets:<EOL><INDENT>if tweet:<EOL><INDENT>tweet['<STR_LIT:text>'] = re.sub('<STR_LIT:http>', '<STR_LIT>', tweet['<STR_LIT:text>'], <NUM_LIT:1>)<EOL>yield tweet<EOL><DEDENT><DEDENT>r = session.get(url, params={'<STR_LIT>': last_tweet}, headers=headers)<EOL>pages += -<NUM_LIT:1><EOL><DEDENT><DEDENT>yield from gen_tweets(pages)<EOL>
Gets tweets for a given user, via the Twitter frontend API.