Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More changes to zotero-upload.py.

  • Loading branch information...
commit a2bc7ae6fff71a040745f7b868b202500e1f9695 1 parent 8035b1c
@jgm authored
Showing with 17 additions and 9 deletions.
  1. +17 −9 zotero-upload.py
View
26 zotero-upload.py
@@ -1,21 +1,20 @@
#!/usr/bin/env python
-# Uploads contents of argv[1] to zotero, with name if specified
+# Uploads contents of stdin with name derived from first argument
# Assumes ZOTERO_KEY and ZOTERO_USER are set
from pyzotero import zotero
# import json
import sys
import os
+import os.path
+import tempfile
if len(sys.argv) < 2:
- sys.stderr.write("Need filename as first argument")
-elif len(sys.argv) == 2:
- filename = sys.argv[1]
- bettername = filename
+ sys.stderr.write("Give filename as first argument")
+ sys.exit(1)
else:
- filename = sys.argv[1]
- bettername = sys.argv[2]
+ nicename = sys.argv[1]
try:
key = os.environ['ZOTERO_KEY']
@@ -34,7 +33,16 @@
# def prettyprint(x):
# print(json.dumps(x, sort_keys=False, indent=2, separators=(',', ': ')))
-zot.attachment_both([(bettername, filename)])
+try:
+ tmpdir = tempfile.mkdtemp()
+ tmpfile = tmpdir + "/" + nicename
+ f = open(tmpfile, 'w')
+ f.write(sys.stdin.read())
+ sys.stdin.flush()
+ f.flush()
+ f.close
+ zot.attachment_simple([tmpfile])
+finally:
+ os.remove(tmpfile)
sys.exit(0)
-

0 comments on commit a2bc7ae

Please sign in to comment.
Something went wrong with that request. Please try again.