Timetric客户端库(http://timetric.com/)

timetric的Python项目详细描述


Timetric(http://timetric.com)的客户端。

需求(易于安装,在setup.py中列为prereq):

  • httplib2
  • python-dateutil
  • simplejson

如果要使用OAuth身份验证,则可以选择:

  • oauth

这是作为prereq列出的not,因此默认情况下不会安装它。

身份验证设置

您将在配置中向TimetricClient提供身份验证信息 Timetric支持两种类型的身份验证:OAuth和API令牌。你 可以使用配置dict的'authtype'键选择方法。 这个键的值可以是'oauth''apitoken';如果没有给它默认值 'oauth'

如果正在使用API令牌,则必须有以下项的密钥:

  • ‘apitoken_key’
  • ‘apitoken_secret’

如果正在使用OAuth,则还必须有以下项的密钥:

  • ‘consumer_key’
  • ‘consumer_secret’

如果你已经做了必要的密钥交换,那么这也可以 包含:

  • ‘access_key’
  • ‘access_token’

OAuth设置

第一次使用oauth协议时,需要进行一些密钥交换 使用Timetric设置您的代币。

>>> import timetric

# You need a config dict with at minimum your secret and key from Timetric # (see the “Applications” pane of the settings page). In a real app you’ll # want to make this config persistant (the shelve module is a lightweight # place to start) because the library will store OAuth authentication # information back to this config. >>> conf = {‘authtype’:’oauth’, … ‘consumer_key: ‘XXX’, … ‘consumer_secret’: ‘XXX’} >>> client = timetric.TimetricClient(conf)

# The first time through you’ll need to authorize your key with Timetric # by sending the user to an authorization request page. >> token = client.get_request_token() >>> import webbrowser >>> webbrowser.open(client.get_authorize_url(token))

# Once the user has authorized at that page, you can continue. >>> access_token = client.get_access_token(token)

# You can now re-authorize to use this token: >>> conf.update({‘oauth_key’:access_token.key, … ‘oauth_secret’:access_token.secret}) >>> client = timetric.TimetricClient(conf)

API令牌设置

>>> import timetric

# Having got your config dict from somewhere: >>> conf = {‘authtype’:’apitoken’, … ‘apitoken_key’: ‘XXX’, .. ‘apitoken-secret’: ‘XXX’}

# you initialize the timetric client: >>> client = timetric.TimetricClient(conf)

用法

# There's no API method to get a list of a particular
# user's series, so you need to somehow "know" the series ID.
>>> series = client.series('p-DpewL0TO-iBE4nMBCTsQ')

# Get the latest value
>>> series.latest()
(1236707269.0, 2.0)

# Iterate over the whole dataset
>>> for (timestamp, value) in series:
...     print timestamp, value
1236463646.39 3.0
1236486562.94 5.0
1236493503.37 6.0

# Update given a single value
>>> series.update(14)

# Update given an iterable of (time, value) pairs
>>> import time
>>> data = [(time.time() - 100, 11), (time.time() + 100, 15)]
>>> series.update(data)

# Update given a file of CSV data
>>> series.update(open('/tmp/data.csv'))

# Clear all the data out of the series
>>> series.delete()

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
无法在Netbeans 8.2 JDK8u231中创建java Maven项目(Web应用程序)   java如何以设定的时间间隔生成随机数?   java从socket和inputStream的慢速读取   spring SCORM:Java中基于Web的SCORM播放器   Java将函数传递给方法   java绑定通用服务及其实现和子类型   java如何在运行时从选择列表框中动态选择选项?爪哇硒   java Selenium WebDriver什么是“Selenium客户端和WebDriver语言绑定”   elasticsearch需要elasticsearch高级Java客户端更新ByQueryRequest API帮助   JAVA哈希表查找最大值   WSDL操作中的java soapAction属性为空   java访问封闭类或父类方法的一般方法   eclipse在java中运行带有SeleneTestCase的ANT。lang.NoClassDefFoundError   java Hazelcast不会在节点启动时填充ReplicatedMap   如何在Java中从excel中读取特定行?   html JAVA将本地时间(GMT+8)转换为UTC时间   java将自定义端点添加到Spring数据REST存储库中,并以大摇大摆的方式显示   java计算未来位置