Skip to content

Instantly share code, notes, and snippets.

@7c00
Created August 5, 2019 02:39
Show Gist options
  • Save 7c00/bf3189e4bacadc7e0e94dc828e1878c3 to your computer and use it in GitHub Desktop.
Save 7c00/bf3189e4bacadc7e0e94dc828e1878c3 to your computer and use it in GitHub Desktop.
Send GitHub Trending via WeChat Work robots. 通过企业微信机器人发送 GitHub Trending.
#!/usr/bin/env python
# coding: utf-8
"""trend.py"""
import logging
import os
import requests
_SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
_TREND_API_URL = 'https://github-trending-api.now.sh/'
_KEY = '<YOUR_KEY>'
_WECHAT_URL = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=' + _KEY
def main():
'''Main entry'''
# Fetch GitHub trending data
data = requests.get(_TREND_API_URL).json()
text = u'# [GitHub Trending](https://github.com/trending) \n\n'
for item in data[:7]:
text += u'> **[{}/{}]({})** ({}\u2B50) {}\n'.format(
item.get('author'),
item.get('name'),
item.get('url'),
item.get('stars'),
item.get('description'))
logging.debug("Text is %s", text)
# Send WeChat message
res = requests.post(_WECHAT_URL, json={
'msgtype': 'markdown',
'markdown': {'content': text}
})
logging.info("Sent alert requests: status_code=%d", res.status_code)
if __name__ == "__main__":
_LOG_FMT = ("%(asctime)s %(levelname)s %(filename)s[line:%(lineno)d]:"
" %(message)s")
_DATE_FMT = "%y/%m/%d %H:%M:%S"
logging.basicConfig(level=logging.DEBUG, format=_LOG_FMT, datefmt=_DATE_FMT)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment