Różnice

Różnice między wybraną wersją a wersją aktualną.

Odnośnik do tego porównania

Poprzednia rewizja po obu stronach Poprzednia wersja
Nowa wersja
Poprzednia wersja
it:scribd_up [2013/11/11 02:18]
naczelnik [Konfiguracja]
it:scribd_up [2014/07/10 18:54] (aktualna)
naczelnik [Kod]
Linia 13: Linia 13:
 </code> </code>
 ====== Konfiguracja ====== ====== Konfiguracja ======
-Tworzymy plik konfiguracyjny zapisując go w jednej z ścieżek:+Pozyskujemy klucz API z http://pl.scribd.com/account-settings/api , a następnie tworzymy plik konfiguracyjny zapisując go w jednej z ścieżek:
   * $PWD/scribd_up.cfg   * $PWD/scribd_up.cfg
   * $HOME/.config/scribd_up.cfg"    * $HOME/.config/scribd_up.cfg" 
Linia 33: Linia 33:
 import ConfigParser import ConfigParser
 from os.path import expanduser from os.path import expanduser
 +import argparse
 +
 +parser = argparse.ArgumentParser()
 +parser.add_argument("-c", "--config", metavar="CFG", 
 +    help="config_file", default=['scribd_up.cfg', expanduser('~/.config/scribd_up.cfg')])
 +parser.add_argument("-p", "--public", action="store_true", default=False,
 +    help="Make docs public",)
 +parser.add_argument("-s","--shortcode", action="store_true",default=False,
 +    help="Output as shortcode",)
 +parser.add_argument('filename', type=file, nargs='+',
 +    help="Files to upload")
 +args =parser.parse_args()
  
 config = ConfigParser.ConfigParser() config = ConfigParser.ConfigParser()
-config.read(['scribd_up.cfg', expanduser('~/.config/scribd_up.cfg')])+config.read(args.config)
  
 scribd.config(config.get('api','key'),config.get('api','secret')) scribd.config(config.get('api','key'),config.get('api','secret'))
Linia 41: Linia 53:
  
 def upload(filename): def upload(filename):
-    document = user.upload(open(filename, 'rb'), access='private',progress_callback=progress)+    access = "public" if args.public else "private" 
 +    document = user.upload(filename, access=access,progress_callback=progress)
     document.save()     document.save()
-    return document.get_scribd_url()+    return document 
 def progress(bytes_sent, bytes_total): def progress(bytes_sent, bytes_total):
     print >> stderr, "\r%s of %s (%s%%)" % (bytes_sent, bytes_total, bytes_sent*100/bytes_total),     print >> stderr, "\r%s of %s (%s%%)" % (bytes_sent, bytes_total, bytes_sent*100/bytes_total),
  
-if len(argv)<2: +for filename in args.filename: 
-    print "Usage:",argv[0],"[file [file [file [...]]]" +    doc = upload(filename
-else+    if args.shortcode: 
-    if len(argv)>2+        att = doc.get_attributes() 
-        for filename in argv[1:]: +        text = "[scribd id=%s key=%s mode=scroll]" % (att['doc_id'],att['access_key']) 
-            url upload(filename+    else: 
-            print "\r",filename, url +        text doc.get_scribd_url()  
-    else: #==2 +    print "\r",filename.nametext
-        print "\r",upload(argv[1])+
 </code> </code>
 ~~DISCUSSION~~ ~~DISCUSSION~~
it/scribd_up.1384132737.txt.gz · ostatnio zmienione: 2013/11/11 02:18 przez naczelnik
Public Domain
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0