|
@ -10,7 +10,6 @@ FIELDNAMES = [ |
|
|
"Publication", |
|
|
"Publication", |
|
|
"Author", |
|
|
"Author", |
|
|
"Year", |
|
|
"Year", |
|
|
"Custodian", |
|
|
|
|
|
"Fields", |
|
|
"Fields", |
|
|
"Type", |
|
|
"Type", |
|
|
"Publishers", |
|
|
"Publishers", |
|
@ -18,7 +17,6 @@ FIELDNAMES = [ |
|
|
"LicenseShort", |
|
|
"LicenseShort", |
|
|
"Highlights", |
|
|
"Highlights", |
|
|
"Comments", |
|
|
"Comments", |
|
|
"Currently borrowed by", |
|
|
|
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -35,6 +33,30 @@ class CsvParser: |
|
|
else: |
|
|
else: |
|
|
return False |
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def _getpublicationfromcsvrow(self, row): |
|
|
|
|
|
"""get entire publication info from a csv row""" |
|
|
|
|
|
year = row["Year"] |
|
|
|
|
|
if not year: |
|
|
|
|
|
year = "Unknown" |
|
|
|
|
|
|
|
|
|
|
|
license = row["License"] |
|
|
|
|
|
if not license: |
|
|
|
|
|
license = "No license mentioned" |
|
|
|
|
|
|
|
|
|
|
|
pubinfo = { |
|
|
|
|
|
"Title": row["Publication"], |
|
|
|
|
|
"Author": row["Author"], |
|
|
|
|
|
"Year": year, |
|
|
|
|
|
"Fields": row["Fields"], |
|
|
|
|
|
"Type": row["Type"], |
|
|
|
|
|
"Publishers": row["Publishers"], |
|
|
|
|
|
"License": license, |
|
|
|
|
|
"Highlights": row["Highlights"], |
|
|
|
|
|
"Comments": row["Comments"], |
|
|
|
|
|
"Image": self._hasimage(row["Id"]), |
|
|
|
|
|
} |
|
|
|
|
|
return pubinfo |
|
|
|
|
|
|
|
|
def parsecsv(self): |
|
|
def parsecsv(self): |
|
|
"""Test function to inspect csv file as dict""" |
|
|
"""Test function to inspect csv file as dict""" |
|
|
libcsv = open(os.path.join(DATA_DIR, self.csv_file), "r") |
|
|
libcsv = open(os.path.join(DATA_DIR, self.csv_file), "r") |
|
@ -116,35 +138,6 @@ class CsvParser: |
|
|
fieldsofinterest[row["Id"]] = fields |
|
|
fieldsofinterest[row["Id"]] = fields |
|
|
return fieldsofinterest |
|
|
return fieldsofinterest |
|
|
|
|
|
|
|
|
def getpublicationfromcsvrow(self, row): |
|
|
|
|
|
"""get entire publication info from a csv row""" |
|
|
|
|
|
year = row["Year"] |
|
|
|
|
|
if not year: |
|
|
|
|
|
year = "Unknown" |
|
|
|
|
|
|
|
|
|
|
|
license = row["License"] |
|
|
|
|
|
if not license: |
|
|
|
|
|
license = "No license mentioned" |
|
|
|
|
|
|
|
|
|
|
|
borrowed = row["Currently borrowed by"] |
|
|
|
|
|
if not borrowed: |
|
|
|
|
|
borrowed = "No one" |
|
|
|
|
|
|
|
|
|
|
|
pubinfo = { |
|
|
|
|
|
"Title": row["Publication"], |
|
|
|
|
|
"Author": row["Author"], |
|
|
|
|
|
"Year": year, |
|
|
|
|
|
"Custodian": row["Custodian"], |
|
|
|
|
|
"Fields": row["Fields"], |
|
|
|
|
|
"Type": row["Type"], |
|
|
|
|
|
"Publishers": row["Publishers"], |
|
|
|
|
|
"License": license, |
|
|
|
|
|
"Highlights": row["Highlights"], |
|
|
|
|
|
"Comments": row["Comments"], |
|
|
|
|
|
"Borrowed": borrowed, |
|
|
|
|
|
"Image": self._hasimage(self, row["Id"]), |
|
|
|
|
|
} |
|
|
|
|
|
return pubinfo |
|
|
|
|
|
|
|
|
|
|
|
def getfullpublication(self, pubid): |
|
|
def getfullpublication(self, pubid): |
|
|
"""For the single book view, most complete overview""" |
|
|
"""For the single book view, most complete overview""" |
|
@ -154,7 +147,7 @@ class CsvParser: |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
csv_as_dict = csv.DictReader(libcsv) |
|
|
for row in csv_as_dict: |
|
|
for row in csv_as_dict: |
|
|
if pubid == row["Id"]: |
|
|
if pubid == row["Id"]: |
|
|
pubinfo = getpublicationfromcsvrow(row) |
|
|
pubinfo = self._getpublicationfromcsvrow(row) |
|
|
|
|
|
|
|
|
# print(pubinfo) |
|
|
# print(pubinfo) |
|
|
return pubinfo |
|
|
return pubinfo |
|
@ -182,7 +175,6 @@ class CsvParser: |
|
|
"Publication": uploadform.uploadpublication.data, |
|
|
"Publication": uploadform.uploadpublication.data, |
|
|
"Author": uploadform.author.data, |
|
|
"Author": uploadform.author.data, |
|
|
"Year": uploadform.year.data, |
|
|
"Year": uploadform.year.data, |
|
|
"Custodian": uploadform.custodian.data, |
|
|
|
|
|
"Fields": uploadform.fields.data, |
|
|
"Fields": uploadform.fields.data, |
|
|
"Type": uploadform.type.data, |
|
|
"Type": uploadform.type.data, |
|
|
"Publishers": uploadform.publishers.data, |
|
|
"Publishers": uploadform.publishers.data, |
|
@ -190,7 +182,6 @@ class CsvParser: |
|
|
"LicenseShort": uploadform.licenseshort.data, |
|
|
"LicenseShort": uploadform.licenseshort.data, |
|
|
"Highlights": uploadform.highlights.data, |
|
|
"Highlights": uploadform.highlights.data, |
|
|
"Comments": uploadform.comments.data, |
|
|
"Comments": uploadform.comments.data, |
|
|
"Currently borrowed by": uploadform.borrowed.data, |
|
|
|
|
|
} |
|
|
} |
|
|
) |
|
|
) |
|
|
print("succesfully written book to csv") |
|
|
print("succesfully written book to csv") |
|
|