1. Dashboard
  2. Forum
    1. Unerledigte Themen
  3. Mitglieder
    1. Letzte Aktivitäten
    2. Benutzer online
    3. Team-Mitglieder
    4. Trophäen
    5. Mitgliedersuche
  4. Tutorial Bereich
  • Anmelden
  • Registrieren
  • Suche
Dieses Thema
  • Alles
  • Dieses Thema
  • Dieses Forum
  • Seiten
  • Forum
  • Lexikon
  • Erweiterte Suche
  1. Informatik Forum
  2. Webmaster & Internet
  3. Entwicklung

amatex -> bibzone

  • Kampi
  • 3. Oktober 2008 um 14:12
  • Unerledigt
  • Kampi
    27
    Kampi
    Mitglied
    Reaktionen
    193
    Punkte
    7.828
    Beiträge
    1.468
    • 3. Oktober 2008 um 14:12
    • #1

    nachdem ich vor monaten mit bedauen feststellen muszte, dass es amatex nicht mehr gibt, habe ich heute mal zeit gefunden ein replacement zu schreiben.

    es gibt sicher einiges zu tun (exceptions, umlaute,...), aber wenn mans nett behandelt, funktioniert es ganz gut (zumindest fuer meine zwecke). vlt. findet es ja jemand hilfreich:

    [edit]
    Changelog:
    version 0.2: language support
    version 0.1: initial release
    [/edit]

    Code
    foobar:~/src/BibZone$ ./bibzone.py --help
    Usage: bibzone.py [options]
    
    
    Options:
      --version             show program's version number and exit
      -h, --help            show this help message and exit
      -k AWSKEY, --awskey=AWSKEY
                            specify your AWS-key
      -a AUTHOR, --author=AUTHOR
                            search by Author
      -t TITLE, --title=TITLE
                            search by Title
      -i ISBN, --isbn=ISBN  search by ISBN
      -c COUNT, --count=COUNT
                            show this number of items
      -l LOCALE, --language=LOCALE
                            search language: fr, ca, de, jp, us, or uk [default:
                            us]
    
    
    foobar:~/src/BibZone$ ./bibzone.py -t python -c 3 -k INSERT_YOUR_KEY
    1) Learning Python, 3rd Edition
            by Mark Lutz
    2) Python in a Nutshell, Second Edition (In a Nutshell (O'Reilly))
            by Alex Martelli
    3) Python Programming: An Introduction to Computer Science
            by John M. Zelle
    Which item do you want? 1
    BibTex-entry:
    @book{lut08,
       author = "Mark Lutz",
       title = "Learning Python, 3rd Edition",
       publisher = "O'Reilly Media, Inc.",
       year = "2008",
       isbn = "0596513984"
    }
    Alles anzeigen
    Python
    #!/usr/bin/env python
    
    
    import sys
    import os.path
    from pyaws import ecs
    """
    http://pyaws.sf.net
    """
    
    
    __version__ = "0.2"
    
    
    
    
    def main():
        from optparse import OptionParser
        cmnd = os.path.basename(sys.argv[0])
    
        parser = OptionParser(version="%prog "+__version__)
    
    
        parser.add_option("-k", "--awskey", dest="awskey", help="specify your AWS-key")
        parser.add_option("-a", "--author", dest="author", help="search by Author")
        parser.add_option("-t", "--title", dest="title", help="search by Title")
        parser.add_option("-i", "--isbn", dest="isbn", help="search by ISBN")
        parser.add_option("-c", "--count", dest="count", help="show this number of items")
        parser.add_option("-l", "--language", default="us", metavar="LOCALE", 
                          help="search language: fr, ca, de, jp, us, "
                          "or uk [default: %default]")
    
    
        (options, args) = parser.parse_args()
    
    
        if options.awskey:
            ecs.setLicenseKey(options.awskey)
        else:
            print "You have to specify an AWS key!"
            print "Get one at: http://aws.amazon.com"
            print "run", cmnd, "--help for additional help"
            sys.exit(1)
    
    
        try:
            ecs.setLocale(options.language)
        except ecs.BadLocale:
            ecs.setLocale("us")
    
    
        if options.count:
            count = int(options.count)
        else:
            count = 20
    
    
        # options are mutually exclusive. isbn >> titel >> author
        if options.isbn:
            books = ecs.ItemLookup(ItemId=options.isbn, IdType='ISBN', SearchIndex='Books', 
                                  ResponseGroup="Medium")
        elif options.title:
            books = ecs.ItemSearch('', SearchIndex='Books', Title=options.title,
                                   ResponseGroup="Medium")
        elif options.author:
            books = ecs.ItemSearch('', SearchIndex='Books', Author=options.author,
                                  ResponseGroup="Medium")
        else:
            print "You have to specify a search query!"
            print "run", cmnd, "--help for additional help"
            sys.exit(1)
    
    
        if len(books) == 0:
            print "Sorry, nothing found"
            sys.exit(0)
    
    
        count = min(count, len(books))
    
    
        #print dir(books[0])
        #sys.exit(0)
    
    
        for i in range(count):
            print "%d) %s" % (i+1,  books[i].Title)
            if type(books[i].Author) == list:
                print "\tby ", " and ".join(books[i].Author)
            else:
                print "\tby %s" % (books[i].Author)
    
    
        itemnumber = int(raw_input("Which item do you want? "))
        itemnumber -= 1
    
    
        if type(books[itemnumber].Author) == list:
            author = " and ".join(books[itemnumber].Author)
            author = author.strip()
        else:
            author = books[itemnumber].Author.strip()
    
    
        author_lastname = author.split()[-1] # last author wins
        title = books[itemnumber].Title.strip()
        publisher = books[itemnumber].Publisher.strip()
        year = books[itemnumber].PublicationDate.strip().split('-')[0]
        isbn = books[itemnumber].ISBN.strip()
    
    
    
    
        # output entry:
        print "BibTex-entry:"
        print "@book{%s%s," % (author_lastname.lower()[:3], year[2:])
        print '   author = "%s",' % (author)
        print '   title = "%s",' % (title)
        print '   publisher = "%s",' % (publisher)
        print '   year = "%s",' % (year)
        print '   isbn = "%s"' % (isbn)
        print "}"
    
    
    if __name__ == "__main__":
        main()
    Alles anzeigen

    Willfähriges Mitglied des Fefe-Zeitbinder-Botnets und der Open Source Tea Party.

    3 Mal editiert, zuletzt von Kampi (7. Oktober 2008 um 11:10)

  • Maximilian Rupp 27. Dezember 2024 um 12:04

    Hat das Thema aus dem Forum Programmieren nach Entwicklung verschoben.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!

Benutzerkonto erstellen Anmelden

Rechtliches

Impressum

Datenschutzerklärung