Last active
October 30, 2017 03:25
-
-
Save mfiers/cfdc69bf8c277cd28974 to your computer and use it in GitHub Desktop.
This file contains 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/bin/env python | |
# | |
# A script to create timestamps using: http://www.originstamp.org | |
# The script has two commands: | |
# "stamp" stamps | |
# | |
# stamper stamp FILENAME [FILENAME [FILENAME...]] | |
# | |
# and "check" checks: | |
# | |
# stamper check FILENAME [FILENAME [FILENAME...]] | |
# | |
### Install: | |
# | |
# The script is written in python 3, and requires the `sh`, `path.py`, | |
# `requests` and `arrow` modules to be installed. | |
# | |
# Also, you will need to request an API key from the following page: | |
# http://www.originstamp.org/developer | |
# | |
# and save the key to ~/.originstamp.key | |
# | |
# This script released under the MIT license | |
# Copyright (c) 2016 Mark Fiers | |
# https://opensource.org/licenses/MIT | |
import sys | |
import json | |
import arrow | |
from sh import sha2 | |
import requests | |
from path import Path | |
with open(Path('~/.originstamp.key').expanduser()) as F: | |
APIKEY = F.read().strip() | |
URL = 'http://www.originstamp.org/api/stamps' | |
HEADERS = {"Authorization": 'Token token="%s"' % APIKEY, | |
"Content-type": "application/json"} | |
command = sys.argv[1] | |
sfiles = sys.argv[2:] | |
if command == 'stamp': | |
for sfile in sfiles: | |
sha = sha2('-256', '-q', sfile, _ok_code=[0,1]).strip() | |
payload = { 'hash_sha256': sha } | |
requests.post(URL, data=json.dumps(payload), headers=HEADERS) | |
print("Stamped: %s" % sfile) | |
elif command == 'check': | |
for sfile in sfiles: | |
sha = sha2('-256', '-q', sfile, _ok_code=[0,1]).strip() | |
url = URL + '/' + sha | |
rsp = requests.get(url, headers=HEADERS) | |
r = rsp.json() | |
print('-' * 80) | |
print('filename :', sfile) | |
print('sha256 :', sha) | |
if r is None: | |
print('##########: NOT FOUND') | |
continue | |
print('title :', r['title']) | |
print('created :', arrow.get(r['created_at']).to('local')) | |
print(' :', arrow.get(r['created_at']).to('local').humanize()) | |
print('updated :', arrow.get(r['updated_at']).to('local')) | |
print(' :', arrow.get(r['updated_at']).to('local').humanize()) | |
if not 'blockchain_transaction' in r: | |
print('submitted : <not yet>') | |
else: | |
bt = r['blockchain_transaction'] | |
trad = Path(sfile).dirname() / 'transact' | |
trad.makedirs_p() | |
sha2tra = trad / '%s.sha2tra' % sha | |
traf = trad / '%s.tra' % bt['tx_hash'] | |
with open(sha2tra, 'w') as F: | |
F.write(bt['tx_hash']) | |
with open(traf, 'w') as F: | |
F.write(str(bt)) | |
print('+++ bitcoin transaction +++') | |
print('tx hash :', bt['tx_hash']) | |
print('recipient :', bt['recipient']) | |
print('public key :', bt['private_key']) | |
print('private key :', bt['public_key']) | |
print('created :', arrow.get(bt['created_at']).to('local')) | |
print(' :', arrow.get(bt['created_at']).to('local').humanize()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this.
But note that this uses the old API which doesn't work any more.
OriginStamp now provides SWIG-generated client code in many languages for download (via a popup - look closely) at https://app.originstamp.org/plugins