Python 查找Twitter中特定话题中最流行的10个转发Tweet
Python 10 查找 转发 特定 流行 twitter 话题
2023-09-11 14:15:00 时间
CODE:
#!/usr/bin/python # -*- coding: utf-8 -*- ''' Created on 2014-7-4 @author: guaguastd @name: find_popular_retweets.py ''' if __name__ == '__main__': # import login, see http://blog.csdn.net/guaguastd/article/details/31706155 from login import twitter_login # get the twitter access api twitter_api = twitter_login() # import search from search import search_for_tweet # import tweet from tweet import popular_retweets # pip install prettytable from prettytable import PrettyTable while 1: query = raw_input('\nInput the query (eg. #MentionSomeoneImportantForYou, exit to quit): ') if query == 'exit': print 'Successfully exit!' break statuses = search_for_tweet(twitter_api, query) retweets = popular_retweets(statuses) # Slice off the first 10 from the sorted results and display each item in the tuple pt = PrettyTable(field_names=['Count', 'Screen Name', 'Text']) [pt.add_row(row) for row in sorted(retweets, reverse=True)[:10]] pt.max_width['Text'] = 50 pt.align = 'l' print pt
RESULT:
Input the query (eg. #MentionSomeoneImportantForYou, exit to quit): #MentionSomeoneImportantForYou Length of statuses 30 +-------+----------------+----------------------------------------------------+ | Count | Screen Name | Text | +-------+----------------+----------------------------------------------------+ | 2 | xmlovex | RT @xmlovex: #MentionSomeoneImportantForYou | | | | @purpledrauhl_23 | | 1 | thuggie_salma | RT @thuggie_salma: "@KillahPimpp: | | | | #MentionSomeoneImportantForYou @thuggie_salma" | | | | baeee
相关文章
- 【Python】python 多线程两种实现方式
- 【学习总结】Python-3-转义字符
- Python正则表达式如何进行字符串替换实例
- 【python cookbook】【数据结构与算法】10.从序列中移除重复项且保持元素间顺序不变
- Python视觉深度学习系列教程 第一卷 第10章 神经网络基础
- 【OpenCV-Python】教程:3-10 直方图(1)查找显示分析
- 华为OD机试 - 数组去重和排序(Java & JS & Python)
- Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Button的command/Label/PhotoImage/封装为类)
- Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(LabelFrame/Checkbutton/Radiobutton)
- 已解决2.Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and wi
- 十年阿里程序员:10个阶段完成python学习计划任务,有教程哦
- 〖Python 数据库开发实战 - Python与MySQL交互篇⑪〗- 项目实战- 完善新闻管理系统中轮询的交互判断
- 【华为OD机试 2023】 密室逃生游戏(C++ Java JavaScript Python)
- Python读excel——xlrd
- 【Leetcode刷题Python】404. 左叶子之和
- 需10道题轻松掌握Python文件处理 | Python技能树征题
- python开发平台Ubuntu