硬币市值公共API加密货币数据记录器
CMCLogger的Python项目详细描述
CMBlocker-硬币市值加密货币数据记录器
一个python API和脚本,用于使用Coin Market Cap Free API请求、解析和存储可用的最新加密货币数据。数据条目存储在SQLite3数据库中,具有用于查询数据和记录器状态的CLI功能。在
TLDR-只是获取一些数据
# Install the module and script pip install CMCLogger # Initialise the required configuration, supplying your API key. (Made above) CMCLogger -a 'your-api-key' -g # Start the logger. Use 'nohup CMCLogger' to start detached, 'CMCLogger &' to start in background. CMCLogger # Query the latest stored price information for ticker 'BTC' CMCLogger -q BTC 'BTC: $11676.55 (3.53%)'# Same as above, but more detailed. CMCLogger -dq BTC 'BTC: $11676.55 1H: -0.22% 1D: 3.53% 7D: 4.77% 24h Volume: 66.65 Billion'# Get the logger status. Health is the moving average success rate of the last 30 calls. CMCLogger -s 'Last successful call 1 minutes ago, health 100.0%.'# Stop the logger CMCLogger -k # Copy the SQLite database to an excel file CMCLogger -x
存储的数据
初始化记录器时,它在$XDG_CONFIG_HOME
内创建一个目录结构。这可以是~/.local/share/CMCLogger
或{echo $XDG_CONFIG_HOME
来查找系统上的位置。在
目录结构如下:
^{pr2}$配置.ini
包含使用的配置参数。更改任何这些设置并重新启动记录器以应用它们。显示的值是默认值。在
[CMC_API]api_private_key=your-private-key-hereconversion_currency=AUDcurreny_symbol=$rank_start_index=1rank_end_index=200request_interval=5[General]status_file_format=ini
加密数据.db
包含记录器检索到的所有数据的SQLite3数据库。数据库包含一个单独的表,名为afeter,表示收集到的每种货币的加密货币符号。SQLitebrower,是浏览数据库的好工具,或者使用CMCLogger -x
将数据库转换为Excel文件进行查看。在
状态.ini
包含有关记录器状态的信息。使用CMCLogger -s
或CMCLogger -ds
时查询并返回此信息
[Last Successful Call]timestamp=2020-04-23 23:10:55.275000+03:00error_code=0error_message=Noneelapsed=17credit_count=1[Last Failed Call]timestamp=2020-04-23 22:39:26.646297+03:00error_code=255error_message=No network connections available.elapsed=0credit_count=0[Current Session]health=100.0successful_calls=35644failed_calls=587success_rate=98.38[All Time]successful_calls=35746failed_calls=589success_rate=98.38
log
Python日志模块存储的运行时日志。在
Polybar/I3WM集成
I3WM
添加到.i3/config
以在登录时启动记录器。在
exec --no-startup-id CMCLogger
Polybar
为目标栏添加polybar模块:
[module/crypto]type= custom/script exec= ~/bin/crypto tail=trueinterval=300
目标脚本只是在一组符号之间循环,如果最后一个条目是在10分钟之前,则返回一个空白字符串。在
#!/bin/bashqueryArray=("BTC""LTC""ETH")TEMPFILE="/tmp/tmp.CMCLOGGER"source$TEMPFILE2> /dev/null function getNextSymbol {position=0for symbol in ${queryArray[@]};do((position++))if[["$symbol"=="$LAST_SYMBOL"]];thensize=${#queryArray[@]}position=$((position%size))CURRENT_SYMBOL=${queryArray[$position]}breakfiCURRENT_SYMBOL=${queryArray[0]}doneecho"LAST_SYMBOL=$CURRENT_SYMBOL" > $TEMPFILE}function checkStatus {jsonStatus=$(CMCLogger -js 2> /dev/null)lastCall=$(echo"$jsonStatus"| jq -r '.last_call')if(($lastCall > 10));thenecho''exitfi} getNextSymbol checkStatus CMCLogger -q $CURRENT_SYMBOL
- 项目
标签: