Created
November 11, 2021 13:08
-
-
Save admorris/977eeec7e50f4a6fde054e6fa2261f18 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env python | |
import requests | |
import csv | |
import datetime as dt | |
def download_table(url="https://gitlab.cern.ch/lhcb-conddb/DDDB/-/raw/master/param/ParticleTable.txt"): | |
r = requests.get(url) | |
r.raise_for_status() | |
lines = r.text.split("\n") | |
return [line.split() for line in filter(lambda x: x and x[0] == " ", lines)] | |
def main(): | |
date = dt.datetime.today().strftime("%Y-%m-%d") | |
table = download_table() | |
lhcb_names = {int(pdg_id): name for name, _, pdg_id, *_ in table} | |
with open("src/particle/lhcb/data/pdgid_to_lhcbname.csv", "w") as out_csv: | |
out_csv.write(f"# (c) Scikit-HEP project - Particle package data file - pdgid_to_lhcbname.csv - {date}\n") | |
writer = csv.DictWriter(out_csv, fieldnames=("PDGID", "STR"), lineterminator="\n") | |
writer.writeheader() | |
for pid,name in sorted(lhcb_names.items(), key=lambda x: (abs(int(x[0])), -int(x[0]))): | |
writer.writerow({"PDGID": pid, "STR": name}) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment