Skip to content

Instantly share code, notes, and snippets.

@anderzzz
Created June 8, 2023 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anderzzz/01c6a157980cca24e0c9c476fde3d8d4 to your computer and use it in GitHub Desktop.
Save anderzzz/01c6a157980cca24e0c9c476fde3d8d4 to your computer and use it in GitHub Desktop.
metadata = {}
with open('your_file_path') as file:
lines = file.readlines()
for line in lines:
if line.startswith('# River:'):
metadata['river'] = line.split(':')[1].strip()
elif line.startswith('# Station:'):
metadata['station'] = line.split(':')[1].strip()
elif line.startswith('# Latitude (DD):'):
metadata['latitude'] = float(line.split(':')[1].strip())
elif line.startswith('# Longitude (DD):'):
metadata['longitude'] = float(line.split(':')[1].strip())
# Print the extracted metadata
for key, value in metadata.items():
print(f"{key}: {value}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment