Thanks to visit codestin.com
Credit goes to gist.github.com

Skip to content

Instantly share code, notes, and snippets.

@toroidal-code
Last active May 3, 2018 20:24
Show Gist options
  • Select an option

  • Save toroidal-code/6415977 to your computer and use it in GitHub Desktop.

Select an option

Save toroidal-code/6415977 to your computer and use it in GitHub Desktop.

Revisions

  1. toroidal-code revised this gist Sep 8, 2013. 2 changed files with 18 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions isbn2.py
    Original file line number Diff line number Diff line change
    @@ -6,8 +6,8 @@

    unit.set(xscale=1.5) # Text scale for pyx

    conn = zoom.Connection('z3950.loc.gov', 7090) # Which server to connect to with ZOOM
    conn.databaseName = 'VOYAGER' # Which database to use
    conn = zoom.Connection('z3950.loc.gov', 7090) # Which server to connect to with ZOOM #albert.rit.edu, 210
    conn.databaseName = 'VOYAGER' # Which database to use #innopac
    conn.preferredRecordSyntax = 'USMARC' # Has to be one of available database record emissions

    while True: # main loop
    16 changes: 16 additions & 0 deletions serverscraper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/usr/bin/env ruby
    require 'nokogiri'
    require 'csv'

    doc = Nokogiri::HTML(`curl http://isbnsearch.sourceforge.net/servers.html`)
    csv = CSV.open("output.csv", 'w')

    doc.xpath('//table//tr').each do |row|
    tarray = [] #temporary array
    row.xpath('td').each do |cell|
    tarray << cell.text #Build array of that row of data.
    end
    csv << tarray #Write that row out to csv file
    end

    csv.close
  2. toroidal-code revised this gist Sep 8, 2013. 1 changed file with 25 additions and 22 deletions.
    47 changes: 25 additions & 22 deletions isbn2.py
    Original file line number Diff line number Diff line change
    @@ -1,26 +1,29 @@
    #! /usr/bin/env python2
    from PyZ3950 import zoom
    from pymarc import MARCReader
    from pyx import *
    import os
    from PyZ3950 import zoom # ZOOM is the protocol
    from pymarc import MARCReader # This is for easily dealing with USMARC data
    from pyx import * # This is for exporting EPS/PDF
    import os # for calling lpr

    unit.set(xscale=1.5)
    conn = zoom.Connection('z3950.loc.gov', 7090)
    conn.databaseName = 'VOYAGER'
    conn.preferredRecordSyntax = 'USMARC'
    while True:
    i = input(">> ")
    query = zoom.Query('CCL', str(i))
    for item in conn.search(query):
    for rec in MARCReader(item.data):
    try:
    print rec.title()
    print rec['050']['a'] # this grabs the LOC call number
    if raw_input("Is this right? (y/n)") is 'y' or 'Y':
    c = canvas.canvas()
    c.text(0.65, 0, rec['050']['a'], [text.halign.boxcenter, trafo.rotate(-90)])
    c.text(0, 0, rec['050']['b'], [text.halign.boxcenter, trafo.rotate(-90)])
    c.writePDFfile()
    os.system("lpr isbn2.pdf")
    unit.set(xscale=1.5) # Text scale for pyx

    conn = zoom.Connection('z3950.loc.gov', 7090) # Which server to connect to with ZOOM
    conn.databaseName = 'VOYAGER' # Which database to use
    conn.preferredRecordSyntax = 'USMARC' # Has to be one of available database record emissions

    while True: # main loop
    i = raw_input(">> ") # grab input
    query = zoom.Query('CCL', str(i)) # send query with input
    for item in conn.search(query): # iterator for query results
    for rec in MARCReader(item.data): # iterator for records in result
    try: # python blows up if the rec['050'] record isn't accessible
    print rec.title() # print title for verification
    print rec['050']['a']
    #ans = raw_input("Is this right? (y/n)")
    #if ans.lower() == 'y':
    c = canvas.canvas()
    c.text(0.65, 0, rec['050']['a'], [text.halign.boxcenter, trafo.rotate(-90)])
    c.text(0, 0, rec['050']['b'], [text.halign.boxcenter, trafo.rotate(-90)])
    c.writePDFfile()
    os.system("lpr isbn2.pdf")
    except TypeError:
    print "Whoops"
  3. toroidal-code revised this gist Sep 7, 2013. 1 changed file with 9 additions and 8 deletions.
    17 changes: 9 additions & 8 deletions isbn2.py
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,10 @@
    #! /usr/bin/env python2
    from PyZ3950 import zoom
    from pymarc import MARCReader

    from pyx import *
    import os



    unit.set(xscale=1.5)
    conn = zoom.Connection('z3950.loc.gov', 7090)
    conn.databaseName = 'VOYAGER'
    conn.preferredRecordSyntax = 'USMARC'
    @@ -15,11 +14,13 @@
    for item in conn.search(query):
    for rec in MARCReader(item.data):
    try:
    print rec.title()
    print rec['050']['a'] # this grabs the LOC call number
    print rec['050']['b'] # This grabs the item number
    c = canvas.canvas()
    c.text(0, 0.5, rec['050']['a'], [text.halign.boxcenter])
    c.text(0, 0, rec['050']['b'], [text.halign.boxcenter])
    c.writePDFfile()
    if raw_input("Is this right? (y/n)") is 'y' or 'Y':
    c = canvas.canvas()
    c.text(0.65, 0, rec['050']['a'], [text.halign.boxcenter, trafo.rotate(-90)])
    c.text(0, 0, rec['050']['b'], [text.halign.boxcenter, trafo.rotate(-90)])
    c.writePDFfile()
    os.system("lpr isbn2.pdf")
    except TypeError:
    print "Whoops"
  4. toroidal-code revised this gist Sep 3, 2013. 1 changed file with 12 additions and 7 deletions.
    19 changes: 12 additions & 7 deletions isbn2.py
    Original file line number Diff line number Diff line change
    @@ -2,19 +2,24 @@
    from PyZ3950 import zoom
    from pymarc import MARCReader

    from pyx import *



    conn = zoom.Connection('z3950.loc.gov', 7090)
    conn.databaseName = 'VOYAGER'
    conn.preferredRecordSyntax = 'USMARC'
    while True:
    text = input(">> ")
    query = zoom.Query('CCL', str(text))
    i = input(">> ")
    query = zoom.Query('CCL', str(i))
    for item in conn.search(query):
    read = MARCReader(item.data)
    for rec in read:
    #print rec.title()
    #print rec.isbn()
    for rec in MARCReader(item.data):
    try:
    print rec['050']['a'] # this grabs the LOC call number
    print rec['050']['b'] # This grabs the item number
    c = canvas.canvas()
    c.text(0, 0.5, rec['050']['a'], [text.halign.boxcenter])
    c.text(0, 0, rec['050']['b'], [text.halign.boxcenter])
    c.writePDFfile()
    except TypeError:
    print "Whoops"
    print "Whoops"
  5. toroidal-code created this gist Sep 2, 2013.
    20 changes: 20 additions & 0 deletions isbn2.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #! /usr/bin/env python2
    from PyZ3950 import zoom
    from pymarc import MARCReader

    conn = zoom.Connection('z3950.loc.gov', 7090)
    conn.databaseName = 'VOYAGER'
    conn.preferredRecordSyntax = 'USMARC'
    while True:
    text = input(">> ")
    query = zoom.Query('CCL', str(text))
    for item in conn.search(query):
    read = MARCReader(item.data)
    for rec in read:
    #print rec.title()
    #print rec.isbn()
    try:
    print rec['050']['a'] # this grabs the LOC call number
    print rec['050']['b'] # This grabs the item number
    except TypeError:
    print "Whoops"