How to use callNumber method in fMBT

Best Python code snippet using fMBT_python

get_callnumber.py

Source:get_callnumber.py Github

copy

Full Screen

1#!/usr/bin/env python32# -*- coding: utf-8 -*-3"""4 example.py5 ~~~~~~~~~6 A simple command line application to run flask apps.7 :copyright: 2019 Miller8 :license: BSD-3-Clause9"""10# Known bugs that can't be fixed here:11# - synopsis() cannot be prevented from clobbering existing12# loaded modules.13# - If the __file__ attribute on a module is a relative path and14# the current directory is changed with os.chdir(), an incorrect15# path will be displayed.16import os17from os import listdir18import click19from marcx import FatRecord20import requests21import re22from bs4 import BeautifulSoup23import json24import tqdm25import re26from os.path import isfile, isdir, join27import logging28# logging.basicConfig(level=logging.INFO,29# format='%(asctime)s - %(levelname)s : %(message)s',30# filename='get_callnumber_log.txt')31# --------------------------------------------------------- common routines32class Boos():33 def __init__(self, id,isbn,callnumber, fail):34 self.id = id35 self.isbn = isbn36 self.callnumber = callnumber37 self.fail = fail38def get_all_filenames():39 # 指定要列出所有檔案的目錄40 mypath = "./marc/"41 # 取得所有檔案與子目錄名稱42 files = listdir(mypath)43 # 以迴圈處理44 # for f in files:45 # # # 產生檔案的絕對路徑46 # # fullpath = join(mypath, f)47 # # # 判斷 fullpath 是檔案還是目錄48 # # if isfile(fullpath):49 # # print("檔案:", f)50 # # elif isdir(fullpath):51 # # print("目錄:", f)52 return files53def get_callnmuber_nbin(isbn):54 """get callnumber form nbin net55 :return:56 """57 # isbn = "9789863125501"58 # url = "http://nbinet3.ncl.edu.tw/search*cht/?searchtype=i&searcharg=9789863125501"59 domain = "http://nbinet3.ncl.edu.tw"60 base_url = "http://nbinet3.ncl.edu.tw/search*cht/?searchtype=i&searcharg="61 # Search List62 #isbn = k['isbn']63 callnum = ""64 try:65 url = base_url + isbn66 res = requests.get(url)67 soup = BeautifulSoup(res.text, "html.parser")68 url_single_book = soup.find_all("span", {"class": "briefcitTitle"})69 ts = url_single_book[1].a70 # Single book page71 url_one = domain + ts['href']72 # print(url_one)73 res_one = requests.get(url_one)74 soup_one = BeautifulSoup(res_one.text, "html.parser")75 field = soup_one.find_all("tr", {"class": "bibItemsEntry"})76 callnum = field[0].a.text77 except:78 pass79 else:80 pass81 return callnum82def get_callnumber_marc(book):83 """get callnumber form marc file84 :return:85 """86 filename = "%s%s-%s.%s" % ('./marc/',book['id'] ,book['isbn'],'marc')87 logging.info("Open file from : {}".format(filename))88 with open(filename,'rb') as fd:89 try:90 record = FatRecord(fd.read())91 except:92 pass93 else:94 tmp_list = list(record.itervalues('200.a','805.d','805.e','805.y'))95 book.update(author = tmp_list[0])96 for i in range(1,3):97 tmp_callnum = ' '.join(tmp_list[i])98 book.update(callnumber = tmp_callnum)99 return tmp_callnum100@click.command()101@click.option('-s', '--isbn', help='Library book ISBN')102def cli(isbn):103 """104 :return:105 """106 # 讀 所有 目錄下的檔名107 # callnumber = get_callnumber_marc()108 row_fail = []109 filenames = get_all_filenames()110 for val in filenames:111 if val.endswith('.fail'):112 fail = "fail"113 else:114 fail = ""115 fields = val.split('.')116 id = fields[0].split('-')[0]117 isbn = fields[0].split('-')[1]118 callnum = "978"119 #print("Fail : {} - {}".format(id, isbn))120 row_fail.append({"id":id,"isbn": isbn,"callnumber":callnum,"fail":fail})121 for k in row_fail:122 if k['fail'] == 'fail':123 print(k['isbn'] + ".fail")124 #k['callnumber'] = get_callnmuber_nbin(k)125 else:126 print(k['isbn'] + '.success' +'--> pass')127 k['callnumber'] = get_callnumber_marc(k)128 ##################129 # search in nbin130 #k['callnumber'] = get_callnmuber_nbin(k['isbn'])131 for i in row_fail:132 #i.update({"callnumber":"999"})133 msg = "{} - {} - {} : {}".format(i['id'], i['isbn'],i["fail"],i["callnumber"])134 print(msg)135 logging.info(msg)136 #filename = "%s%s-%s.%s" % ('./marc/', i['id'], i['isbn'], 'marc')137 file_save = './bookshelf_callnumber.txt'138 with open(file_save,'w',encoding="UTF-8") as fd:139 print("Save to book: %s" % file_save)140 json.dump(row_fail,fd)141if __name__ == '__main__':...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1import unittest2import callnumber3lccns = {4 'HE8700.7 .P6T44 1983': ['HE', '8700.7', '.P6', 'T44', '1983'],5 'BS2545.E8 H39 1996': ['BS', '2545', '.E8', 'H39', '1996'],6 'NX512.S85 A4 2006': ['NX', '512', '.S85', 'A4', '2006'],7}8lccns_with_blanks = {9 'HE8700.7 .P6T44 1983': ['HE', '8700.7', '.P6', 'T44', '', '1983'],10 'BS2545.E8 1996': ['BS', '2545', '.E8', '', '', '1996'],11 'NX512.S85 A4': ['NX', '512', '.S85', 'A4', '', ''],12}13class CallNumberTest(unittest.TestCase):14 def test_00_simple_normalization(self):15 lccn = callnumber.LC('A')16 self.assertTrue(lccn.denormalized, 'A')17 self.assertTrue(lccn.normalized, 'A')18 def test_01_compound_normalization(self):19 lccn = callnumber.LC('A11.1')20 self.assertTrue(lccn.denormalized, 'A11.1')21 self.assertTrue(lccn.normalized, 'A 001110')22 def test_02_normalize_module_method(self):23 self.assertTrue(callnumber.normalize('B11'), 'B 0011')24 def test_03_module_method_with_cutters(self):25 self.assertTrue(callnumber.normalize('A 123.4 .c11'), 'A 012340C110')26 self.assertTrue(callnumber.normalize('B11 .c13 .d11'),27 'B 001100C130D110')28 self.assertTrue(callnumber.normalize('B11 .c13 .d11'),29 'B 001100C130D119~999')30 def test_04_simple_range(self):31 lccn = callnumber.LC('A')32 self.assertTrue(lccn.range_start, 'A')33 self.assertTrue(lccn.range_end, 'A~~')34 def test_05_compound_range(self):35 lccn = callnumber.LC('A11.1')36 self.assertTrue(lccn.range_start, 'A 001110')37 self.assertTrue(lccn.range_end, 'A 001119~999~999~999')38 def test_06_start_of_range_equivalence(self):39 for lccn in lccns:40 lccn = callnumber.LC(lccn)41 self.assertTrue(lccn.normalized, lccn.range_start)42 def test_07_components_no_blanks(self):43 for lccn in lccns:44 expected = lccns[lccn]45 comps = callnumber.LC(lccn).components()46 self.assertTrue(lccn)47 self.assertEqual(len(expected), len(comps))48 self.assertEqual(expected, comps)49 def test_08_components_no_blanks(self):50 for lccn in lccns_with_blanks:51 expected = lccns_with_blanks[lccn]52 comps = callnumber.LC(lccn).components(include_blanks=True)53 self.assertTrue(lccn)54 self.assertEqual(len(expected), len(comps))55 self.assertEqual(expected, comps)56def suite():57 test_suite = unittest.makeSuite(CallNumberTest, 'test')58 return test_suite59if __name__ == '__main__':...

Full Screen

Full Screen

test_number.py

Source:test_number.py Github

copy

Full Screen

...33 self.cls = JClass("jpype.common.Fixture")34 self.fixture = self.cls()35 def testJavaPrimitives(self):36 self.assertIsInstance(37 self.fixture.callNumber(JByte(1)), java.lang.Byte)38 self.assertIsInstance(39 self.fixture.callNumber(JShort(1)), java.lang.Short)40 self.assertIsInstance(41 self.fixture.callNumber(JInt(1)), java.lang.Integer)42 self.assertIsInstance(43 self.fixture.callNumber(JLong(1)), java.lang.Long)44 self.assertIsInstance(45 self.fixture.callNumber(JFloat(1)), java.lang.Float)46 self.assertIsInstance(self.fixture.callNumber(47 JDouble(1)), java.lang.Double)48 def testPythonPrimitives(self):49 self.assertIsInstance(self.fixture.callNumber(1), java.lang.Long)50 self.assertIsInstance(self.fixture.callNumber(1.0), java.lang.Double)51 @common.requireNumpy52 def testNumpyPrimitives(self):53 self.assertIsInstance(54 self.fixture.callNumber(np.int8(1)), java.lang.Byte)55 self.assertIsInstance(self.fixture.callNumber(56 np.int16(1)), java.lang.Short)57 self.assertIsInstance(self.fixture.callNumber(58 np.int32(1)), java.lang.Integer)59 self.assertIsInstance(self.fixture.callNumber(60 np.int64(1)), java.lang.Long)61 self.assertIsInstance(self.fixture.callNumber(62 np.float32(1)), java.lang.Float)63 self.assertIsInstance(self.fixture.callNumber(...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run fMBT automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful