<jupyter_start><jupyter_text>Öffnen und Analyse der Datei  Importieren des csv-Moduls<jupyter_code>import csv<jupyter_output><empty_output><jupyter_text>Öffnen der Datei als Variable<jupyter_code>file = open("./aussonderung.csv", "r")<jupyter_output><empty_output><jupyter_text>Verifizierung des Typs<jupyter_code>type(file)
print(file)<jupyter_output><_io.TextIOWrapper name='./aussonderung.csv' mode='r' encoding='cp1252'><jupyter_text>Anzeigen des Inhaltes<jupyter_code>content = file.readlines()
content<jupyter_output><empty_output><jupyter_text>Kürzeres Öffnen der Datei als Liste samt Festlegung einer Variable<jupyter_code>with open('./aussonderung.csv', 'r') as infile:
    titles = infile.readlines()<jupyter_output><empty_output><jupyter_text>Verifizierung des Typs<jupyter_code>type(titles)<jupyter_output><empty_output><jupyter_text>Anzeige der Liste<jupyter_code>titles<jupyter_output><empty_output><jupyter_text>Anzahl der Listenelemente<jupyter_code>print(len(titles))<jupyter_output>4<jupyter_text>Anzeige der Listenelemente<jupyter_code>for item in titles:
    print(item)<jupyter_output>HT019793989

HT020379995

HT020319679

HT014682026<jupyter_text>Alternatives Öffnen der Datei und Kürzung der Strings der Listenelemente<jupyter_code>with open('./aussonderung.csv', 'r') as infile:
    for line in infile:
        print(line.strip())<jupyter_output>HT019793989
HT020379995
HT020319679
HT014682026<jupyter_text>Kurzversion<jupyter_code>for line in open('./aussonderung.csv', 'r'):
    print(line.strip())<jupyter_output>HT019793989
HT020379995
HT020319679
HT014682026<jupyter_text>Schleifenabfrage  Festlegung der Variable für die Grund-URL der verwendeten API<jupyter_code>url = 'https://lobid.org/resources/'<jupyter_output><empty_output><jupyter_text>Anzeige der zusammengesetzten URLs aus Grund-URL und HT-Nummern aus der Liste<jupyter_code>for item in titles:
    nexturl=url+item
    print(nexturl)<jupyter_output>https://lobid.org/resources/HT019793989

https://lobid.org/resources/HT020379995

https://lobid.org/resources/HT020319679

https://lobid.org/resources/HT014682026<jupyter_text>Importieren des requests-Moduls<jupyter_code>import requests<jupyter_output><empty_output><jupyter_text>Schleifenabfrage und Verifizierung<jupyter_code>for item in titles:
    r = requests.get(url + line.strip())
    print(r)<jupyter_output><Response [200]>
<Response [200]>
<Response [200]>
<Response [200]><jupyter_text>Anzeige des Typs<jupyter_code>type(r)<jupyter_output><empty_output><jupyter_text>Anzeige Status Code<jupyter_code>r.status_code<jupyter_output><empty_output><jupyter_text>Anzeige Header<jupyter_code>r.headers<jupyter_output><empty_output><jupyter_text>Anzeige des Content Types des Headers<jupyter_code>r.headers['Content-Type']<jupyter_output><empty_output><jupyter_text>Schleifenabfrage mit dem erfolgreichen Versuch, sämtliche Titel anzeigen zu lassen<jupyter_code>for line in open('./aussonderung.csv', 'r'):
    r = requests.get('https://lobid.org/resources/'+line.strip())
    print(r.text)
r.text<jupyter_output><empty_output><jupyter_text>Sortierung und Analyse eines Response Objektes  json-Modul importieren<jupyter_code>import json<jupyter_output><empty_output><jupyter_text>Variable festlegen für das json-Objekt<jupyter_code>data = r.json()<jupyter_output><empty_output><jupyter_text>Typ des json-Objektes anzeigen lassen<jupyter_code>type(data)<jupyter_output><empty_output><jupyter_text>Dictionary anzeigen<jupyter_code>print(data)<jupyter_output>{'type': ['BibliographicResource', 'Book'], 'contribution': [{'type': ['Contribution'], 'agent': {'id': 'https://d-nb.info/gnd/115539778', 'type': ['Person'], 'label': '<NAME>', 'dateOfBirth': '1964', 'gndIdentifier': '115539778'}, 'role': {'id': 'http://id.loc.gov/vocabulary/relators/cre', 'label': 'Autor/in'}}], 'extent': '218 S.', 'hasItem': [{'id': 'http://lobid.org/items/HT014682026:DE-708:OCW%2FHECK#!', 'type': ['Item'], 'heldBy': {'id': 'http://lobid.org/organisations/DE-708#!', 'label': 'lobid Organisation'}, 'note': '00', 'callNumber': 'OCW/HECK', 'label': 'OCW/HECK'}, {'id': 'http://lobid.org/items/HT014682026:DE-361:CQ950%20H448#!', 'type': ['Item'], 'heldBy': {'id': 'http://lobid.org/organisations/DE-361#!', 'label': 'lobid Organisation'}, 'note': '00000014', 'callNumber': 'CQ950 H448', 'label': 'CQ950 H448'}, {'id': 'http://lobid.org/items/HT014682026:DE-82:LF1565#!', 'type': ['Item'], 'heldBy': {'id': 'http://lobid.org/organisations/DE-82#!', 'label': 'lobid Organ[...]<jupyter_text>In human-readable Form bringen<jupyter_code>print(json.dumps(data, indent=2))<jupyter_output>{
  "type": [
    "BibliographicResource",
    "Book"
  ],
  "contribution": [
    {
      "type": [
        "Contribution"
      ],
      "agent": {
        "id": "https://d-nb.info/gnd/115539778",
        "type": [
          "Person"
        ],
        "label": "<NAME>",
        "dateOfBirth": "1964",
        "gndIdentifier": "115539778"
      },
      "role": {
        "id": "http://id.loc.gov/vocabulary/relators/cre",
        "label": "Autor/in"
      }
    }
  ],
  "extent": "218 S.",
  "hasItem": [
    {
      "id": "http://lobid.org/items/HT014682026:DE-708:OCW%2FHECK#!",
      "type": [
        "Item"
      ],
      "heldBy": {
        "id": "http://lobid.org/organisations/DE-708#!",
        "label": "lobid Organisation"
      },
      "note": "00",
      "callNumber": "OCW/HECK",
      "label": "OCW/HECK"
    },
    {
      "id": "http://lobid.org/items/HT014682026:DE-361:CQ950%20H448#!",
      "type": [
        "Item"
      ],
      "heldBy": {
        "id": "http://l[...]<jupyter_text>Anzeigen der Schlüsselwerte<jupyter_code>print(data.keys())<jupyter_output>dict_keys(['type', 'contribution', 'extent', 'hasItem', 'responsibilityStatement', 'description', 'language', 'medium', 'subject', 'tableOfContents', 'title', 'hbzId', 'subjectAltLabel', 'isbn', 'oclcNumber', 'otherTitleInformation', 'publication', 'sameAs', 'describedBy', '@context', 'id'])<jupyter_text>Festlegen der Variable für den zu untersuchenden Key<jupyter_code>holding = data['hasItem']<jupyter_output><empty_output><jupyter_text>Typ des Keys anzeigen<jupyter_code>print(type(holding))<jupyter_output><class 'list'><jupyter_text>Anzahl der Elemente in der Liste ausgeben<jupyter_code>print(len(holding))<jupyter_output>12<jupyter_text>Variable für die Anzahl der Elemente aus der Liste festlegen<jupyter_code>x = len(holding)<jupyter_output><empty_output><jupyter_text>Prüfung, ob die zu untersuchende Bedingung erfüllt ist<jupyter_code>if x > 1 == True:
    print("True")
else:
    print("False")<jupyter_output>True<jupyter_text>Ausgabe der Ergebnisse  Festlegung der Variable für den Key, aus dem die zu schreibende HT-Nummer entnommen wird<jupyter_code>ht = data['id']<jupyter_output><empty_output><jupyter_text>Anzeige des Ausgabe-Wertes<jupyter_code>print(ht)<jupyter_output>http://lobid.org/resources/HT014682026#!<jupyter_text>Kürzung auf den zu schreibenden Wert in zwei Schritten<jupyter_code>ht_strip = ht.strip("http://lobid.org/resources/")
print(ht_strip)
ht_number = ht_strip.strip("#!")
print(ht_number)<jupyter_output>HT014682026<jupyter_text>Bedingung für das Schreiben des Wertes in die jeweilige Ausgabe-Datei<jupyter_code>if x > 1 == True:
    with open('./loeschliste.csv', 'w') as outfile1:
        outfile1.writelines(ht_number)
else:
    with open('./alleinbesitz.csv', 'w') as outfile2:
        outfile2.writelines(ht_number)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15942803688360282, 'fraction_numerical': 0.047307229720700256, 'mean_word_length': 6.380670611439842, 'pattern_counts': {'":': 26, '<': 134, '<?xml version=': 0, '>': 136, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '35', 'dir': 'jupyter-structured-clean-dedup', 'id': '318584', 'license': 'CC0-1.0', 'n_tokens_mistral': 3160, 'n_tokens_neox': 2925, 'n_words': 418, 'path': '01-Data_Librarian_Project _-_ Automized_query_long_commented.ipynb', 'repo_name': 'ng78/Data_Librarian_Project', 'size': '7499'}