Created
October 24, 2017 07:58
-
-
Save Arcanemagus/1d3f1fde0d1f9a88d5890d236b80eefb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/python2.7 | |
| import os | |
| import sys | |
| import json | |
| import requests | |
| webhook_id = "foo" | |
| webhook_token = "bar" | |
| program = {} | |
| torrent = {} | |
| if len(sys.argv) == 3: | |
| program['name'] = sys.argv[1] | |
| torrent['title'] = sys.argv[2] | |
| elif os.getenv('TR_APP_VERSION') is not None: | |
| program['name'] = 'Transmission' | |
| program['version'] = os.getenv('TR_APP_VERSION') | |
| torrent['title'] = os.getenv('TR_TORRENT_NAME', 'Unknown') | |
| torrent['hash'] = os.getenv('TR_TORRENT_HASH') | |
| torrent['directory'] = os.getenv('TR_TORRENT_DIR') | |
| torrent['localtime'] = os.getenv('TR_TIME_LOCALTIME') | |
| torrent['id'] = os.getenv('TR_TORRENT_ID') | |
| else: | |
| print 'Usage:' | |
| print '* Call from Transmission with no parameters' | |
| print '* discord-notify program torrent_title' | |
| sys.exit() | |
| headers = { | |
| 'Content-Type': 'application/json' | |
| } | |
| url = 'https://discordapp.com/api/webhooks/' + webhook_id + '/' + webhook_token | |
| data = { | |
| 'content': '"' + torrent['title'] + '" has finished downloading.' | |
| } | |
| attachment = { | |
| 'fields': [ | |
| { 'name': 'Torrent', 'value': torrent['title'], 'inline': False }, | |
| { 'name': 'Program', 'value': program['name'], 'inline': False } | |
| ] | |
| } | |
| data['embeds'] = [attachment] | |
| if 'version' in program: | |
| attachment['fields'].append({ | |
| 'name': 'Version', 'value': program['version'], 'inline': True }) | |
| if 'hash' in torrent: | |
| attachment['fields'].append({ | |
| 'name': 'Hash', 'value': torrent['hash'], 'inline': False }) | |
| if 'directory' in torrent: | |
| attachment['fields'].append({ | |
| 'name': 'Directory', 'value': torrent['directory'], 'inline': False }) | |
| response = requests.post(url, headers=headers, data=json.dumps(data)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment