-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
147 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import xml.etree.ElementTree as ET | ||
import json | ||
|
||
# Read XML content from a file | ||
file_path = 'ccv_patents.xml' | ||
|
||
# Parse the XML content | ||
tree = ET.parse(file_path) | ||
root = tree.getroot() | ||
|
||
# Create a list to hold the converted data | ||
data = [] | ||
|
||
# Iterate through each 'section' in the XML | ||
for section in root.findall('section'): | ||
section_data = {} | ||
|
||
# Get values from the fields within each section | ||
for field in section.findall('field'): | ||
label = field.get('label') | ||
value = field.find('value') | ||
lov = field.find('lov') | ||
if value is not None and value.text: | ||
section_data[label.lower().replace(' ', '_')] = value.text.strip() | ||
elif lov is not None and lov.text: | ||
section_data[label.lower().replace(' ', '_')] = lov.text.strip() | ||
|
||
# Extract inventors list and get the first inventor | ||
inventors_list = section_data.get("inventors", "").split(';') | ||
first_inventor = inventors_list[0].strip() if inventors_list else "" | ||
|
||
# Create the desired JSON structure | ||
formatted_data = { | ||
"type": "patent", | ||
"key": f"{first_inventor.lower().replace(' ', '')}{section_data.get('filing_date', '').split('-')[0]}patent", | ||
"title": section_data.get("patent_title", ""), | ||
"status": section_data.get("patent_status", "").lower(), | ||
"filed": section_data.get("filing_date", ""), | ||
"authors": [author.strip() for author in inventors_list], | ||
"patent_number": section_data.get("patent_number", "") | ||
} | ||
|
||
# Append formatted data to the list | ||
data.append(formatted_data) | ||
|
||
# Convert the list of dictionaries to JSON | ||
json_data = json.dumps(data, indent=2) | ||
|
||
# Write JSON data to a file | ||
with open('converted_data.json', 'w') as json_file: | ||
json_file.write(json_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import xml.etree.ElementTree as ET | ||
import json | ||
|
||
# Read XML content from a file | ||
file_path = 'ccv_talks.xml' | ||
|
||
# Parse the XML content | ||
tree = ET.parse(file_path) | ||
root = tree.getroot() | ||
|
||
# Create a list to hold the converted data | ||
data = [] | ||
|
||
# Iterate through each 'section' in the XML | ||
for section in root.findall('section'): | ||
section_data = {} | ||
|
||
# Get values from the fields within each section | ||
for field in section.findall('field'): | ||
label = field.get('label') | ||
value = field.find('value') | ||
lov = field.find('lov') | ||
if value is not None and value.text: | ||
section_data[label.lower()] = value.text | ||
elif lov is not None and lov.text == 'Yes': | ||
section_data[label.lower()] = 'Yes' | ||
|
||
# if "keynote?" in section_data: | ||
# print(section_data.get("keynote?", "").lower()) | ||
|
||
# Create the desired JSON structure | ||
formatted_data = { | ||
"title": section_data.get("presentation title", ""), | ||
"event": section_data.get("conference / event name", ""), | ||
"location": f"{section_data.get('city', '')} ({section_data.get('location', '')})", | ||
"year": section_data.get("presentation year", ""), | ||
"keynote": section_data.get("keynote?", "").lower() if "keynote?" in section_data else "no" | ||
} | ||
|
||
# Append formatted data to the list | ||
data.append(formatted_data) | ||
|
||
# Convert the list of dictionaries to JSON | ||
json_data = json.dumps(data, indent=2) | ||
|
||
# Write JSON data to a file | ||
with open('ccv_talks.json', 'w') as json_file: | ||
json_file.write(json_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import json | ||
|
||
# Read JSON content from a file | ||
file_path = 'ccv_talks.json' | ||
|
||
# Read JSON data from file | ||
with open(file_path, 'r') as json_file: | ||
data = json.load(json_file) | ||
|
||
# Iterate through each entry in the JSON data | ||
for entry in data: | ||
template = """\\item \\ressubheading{event}{location}{title}{year}""" | ||
template = template.replace("event", entry['event']) | ||
template = template.replace("location", entry['location']) | ||
template = template.replace("title", entry['title']) | ||
template = template.replace("year", entry['year']) | ||
print(template) |