跳转到主要内容

Python的Twitter相关辅助函数集合。

项目描述

Build Status

Twitwi

Python的Twitter相关辅助函数集合。

安装

您可以使用以下命令使用pip安装twitwi

pip install twitwi

用法

规范化函数

格式化函数

有用的常量(在twitwi.constants下)

normalize_tweets_payload_v2

函数接受v2 API的整个推文负载,并返回包含已规范化并结构化的推文列表,以便进一步分析数据。

from twitwi import normalize_tweets_payload_v2

# Normalizing an entire tweets payload to extract a list of tweets
normalize_tweets_payload_v2(payload)

# Normalizing an entire tweets payload to extract a list of tweets
# as well as the referenced tweets (quoted, retweeted, etc.)
normalize_tweets_payload_v2(payload, extract_referenced_tweets=True)

# Converting found dates to a chosen timezone
from pytz import timezone
paris_tz = timezone('Europe/Paris')

normalize_tweets_payload_v2(payload, locale=paris_tz)

参数

  • payload (dict):来自Twitter API v2的推文负载。
  • locale (pytz.timezone, 可选):用于转换日期的时间区域。如果没有提供,将默认为UTC。
  • extract_referenced_tweets (bool, 可选):是否在输出中保留引用推文(转推、引用等)。默认为False
  • collection_source *(字符串,可选):向推文添加的可选信息,以表明您从何处收集了它们。

transform_tweet_into_csv_dict

将给定的规范化推文转换为可由 csv.DictWriter 写入行的字典的函数(即修改,请注意)。

from twitwi import transform_tweet_into_csv_dict

# The function returns nothing, `normalized_tweet` has been mutated
transform_tweet_into_csv_dict(normalized_tweet)

transform_user_into_csv_dict

将给定的规范化Twitter用户转换为可由 csv.DictWriter 写入行的字典的函数(即修改,请注意)。

from twitwi import transform_user_into_csv_dict

# The function returns nothing, `normalized_user` has been mutated
transform_user_into_csv_dict(normalized_user)

format_tweet_as_csv_row

将给定的规范化推文格式化为列表,以便可由 csv.writer 写入行。

from twitwi import format_tweet_as_csv_row

row = format_tweet_as_csv_row(normalized_tweet)

format_user_as_csv_row

将给定的规范化Twitter用户格式化为列表,以便可由 csv.writer 写入行。

from twitwi import format_user_as_csv_row

row = format_user_as_csv_row(normalized_user)

TWEET_FIELDS

推文字段名列表。用于使用csv写入器声明标题

from twitwi.constants import TWEET_FIELDS

# Using csv.writer
w = csv.writer(f)
w.writerow(TWEET_FIELDS)

# Using csv.DictWriter
w = csv.DictWriter(f, fieldnames=TWEET_FIELDS)
w.writeheader()

USER_FIELDS

from twitwi.constants import USER_FIELDS

# Using csv.writer
w = csv.writer(f)
w.writerow(USER_FIELDS)

# Using csv.DictWriter
w = csv.DictWriter(f, fieldnames=USER_FIELDS)
w.writeheader()

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分布

twitwi-0.19.2.tar.gz (18.0 kB 查看散列)

上传时间

构建分布

twitwi-0.19.2-py3-none-any.whl (19.1 kB 查看散列)

上传时间 Python 3

由以下赞助

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面