From 0a15444366c39c70e4a5b8eb08538c862de9f6ae Mon Sep 17 00:00:00 2001 From: MiranDaniel Date: Wed, 29 Oct 2025 23:16:08 +0100 Subject: [PATCH] Licensing, README, API fix... --- .gitignore | 1 + LICENSE | 131 +++++++++++++++++++++++ README.md | 41 ++++++- combogen/ChartGenerator.py | 3 + combogen/DrugDatabase.py | 18 +++- combogen/templates/combo-chart-full.html | 4 +- combogen/templates/legend.html | 5 +- config.json | 2 +- requirements.txt | 2 + resources/css/style.css | 2 +- 10 files changed, 200 insertions(+), 9 deletions(-) create mode 100644 LICENSE create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 4c25636..9fc4eec 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ __pycache__/ npm-debug.log node_modules/ .vscode/settings.json +*.pyc diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b5b976b --- /dev/null +++ b/LICENSE @@ -0,0 +1,131 @@ +# PolyForm Noncommercial License 1.0.0 + + + +## Acceptance + +In order to get any license under these terms, you must agree +to them as both strict obligations and conditions to all +your licenses. + +## Copyright License + +The licensor grants you a copyright license for the +software to do everything you might do with the software +that would otherwise infringe the licensor's copyright +in it for any permitted purpose. However, you may +only distribute the software according to [Distribution +License](#distribution-license) and make changes or new works +based on the software according to [Changes and New Works +License](#changes-and-new-works-license). + +## Distribution License + +The licensor grants you an additional copyright license +to distribute copies of the software. Your license +to distribute covers distributing the software with +changes and new works permitted by [Changes and New Works +License](#changes-and-new-works-license). + +## Notices + +You must ensure that anyone who gets a copy of any part of +the software from you also gets a copy of these terms or the +URL for them above, as well as copies of any plain-text lines +beginning with `Required Notice:` that the licensor provided +with the software. For example: + +> Required Notice: Copyright TripSit (Callum Macdonald) 2022 + +## Changes and New Works License + +The licensor grants you an additional copyright license to +make changes and new works based on the software for any +permitted purpose. + +## Patent License + +The licensor grants you a patent license for the software that +covers patent claims the licensor can license, or becomes able +to license, that you would infringe by using the software. + +## Noncommercial Purposes + +Any noncommercial purpose is a permitted purpose. + +## Personal Uses + +Personal use for research, experiment, and testing for +the benefit of public knowledge, personal study, private +entertainment, hobby projects, amateur pursuits, or religious +observance, without any anticipated commercial application, +is use for a permitted purpose. + +## Noncommercial Organizations + +Use by any charitable organization, educational institution, +public research organization, public safety or health +organization, environmental protection organization, +or government institution is use for a permitted purpose +regardless of the source of funding or obligations resulting +from the funding. + +## Fair Use + +You may have "fair use" rights for the software under the +law. These terms do not limit them. + +## No Other Rights + +These terms do not allow you to sublicense or transfer any of +your licenses to anyone else, or prevent the licensor from +granting licenses to anyone else. These terms do not imply +any other licenses. + +## Patent Defense + +If you make any written claim that the software infringes or +contributes to infringement of any patent, your patent license +for the software granted under these terms ends immediately. If +your company makes such a claim, your patent license ends +immediately for work on behalf of your company. + +## Violations + +The first time you are notified in writing that you have +violated any of these terms, or done anything with the software +not covered by your licenses, your licenses can nonetheless +continue if you come into full compliance with these terms, +and take practical steps to correct past violations, within +32 days of receiving notice. Otherwise, all your licenses +end immediately. + +## No Liability + +***As far as the law allows, the software comes as is, without +any warranty or condition, and the licensor will not be liable +to you for any damages arising out of these terms or the use +or nature of the software, under any kind of legal claim.*** + +## Definitions + +The **licensor** is the individual or entity offering these +terms, and the **software** is the software the licensor makes +available under these terms. + +**You** refers to the individual or entity agreeing to these +terms. + +**Your company** is any legal entity, sole proprietorship, +or other kind of organization that you work for, plus all +organizations that have control over, are under the control of, +or are under common control with that organization. **Control** +means ownership of substantially all the assets of an entity, +or the power to direct its management and policies by vote, +contract, or otherwise. Control can be direct or indirect. + +**Your licenses** are all the licenses granted to you for the +software under these terms. + +**Use** means anything you do with the software requiring one +of your licenses. diff --git a/README.md b/README.md index 7107086..948345e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,18 @@ +# combogen + +Combogen is an application that generates drug combo charts as PNG and PDF files to help users know the results and safety of drug combinations. + +This repository does not contain the raw combination data, it is a simple image/PDF generator. The data is fetched from the [TripSit/drugs](https://github.com/TripSit/drugs) repository ([drugs.json](https://github.com/TripSit/drugs/blob/main/drugs.json)). + +Output example (uses historamical data, not up to date): +![Example output](https://wiki.tripsit.me/images/3/3a/Combo_2.png) + ## Dependencies - Install [Python 3](https://www.python.org), [Node.js](https://nodejs.org), and [npm](https://www.npmjs.com). -- Afterwards make sure `python` (or `python3`), `node`, `npm` are in your `PATH`. -- Install required python modules: `pip3 install requests jinja2` +- Afterwards make sure `python` (or `python3`), `node`, `npm`, `pip` are in your `PATH`. +- Move into the project directory using `cd` +- Create a virtual environment: `python3 -m venv venv` +- Install the required Python packages: `./venv/bin/pip3 install -r requirements.txt` ### Google Chrome Some of the used npm packages may want to use Google Chrome or Chromium. If you need to install it depends on your operating system. It's not needed on macOS 13.4. for example. @@ -15,7 +26,7 @@ After installing Chrome, make sure `google-chrome` or `chrome` are in your `PATH - `git clone` this repo - `cd` to the project dir - Run `npm install` -- Run `python -m combogen` (or `python3 -m combogen`) +- Run `./venv/bin/python3 -m combogen` ## How to configure - Edit **config.json** @@ -25,3 +36,27 @@ After installing Chrome, make sure `google-chrome` or `chrome` are in your `PATH - Run the script (see above) - PNGs are located in output/png/ - PDFs are located in output/pdf/ + +## Troubleshooting common issues + +### Result shows NXDRUG instead of real info + +This means that the drug is not defined in the source json that the app uses to generate the chart. +The drug was most likely renamed/changed by accident in the [source data](https://github.com/TripSit/drugs/blob/main/drugs.json) or this project. +Check the lastest commit in the project to see if there was any breaking change made. +Please report the issue on our [Discord](https://discord.gg/tripsit). +You can use an older version of [drugs.json](https://github.com/TripSit/drugs/blob/main/drugs.json) as a temporary fix, simply edit the source in `config.json`. + +## Contibuting + +The easiest way to contribute is to translate the chart into your language. +You may find the translation data in the `combogen/translations/` directory. +Please use common (not complex) language and drug names to make the chart easily understandable by everyone. + +## Licensing + +Big thanks to everyone who contributed—this project wouldn’t be what it is without your help! + +--- + +This project is licensed under the **PolyForm Noncommercial License**. Here is a (non legally binding TL;DR, find the full licence in the `LICENSE` file): *You can use, modify, and share this project freely **for noncommercial purposes only**. Any commercial use requires a separate license. Use by any charitable organization, educational institution, public research organization, public safety or health organization, environmental protection organization, or government institution is considered a permitted purpose **regardless of funding sources**. The project is provided **as-is**, with no warranties, and you must include this license if you redistribute it.* diff --git a/combogen/ChartGenerator.py b/combogen/ChartGenerator.py index ef93727..10d36bd 100644 --- a/combogen/ChartGenerator.py +++ b/combogen/ChartGenerator.py @@ -24,6 +24,9 @@ def generate(self, lang): status_msg = "Version {} — ".format(self._config.version) status_msg += "Generated on {} at {} UTC".format(time_generated.strftime("%d %b %Y"), time_generated.strftime("%H:%M")) + + if self._db._data_update_time is not Ellipsis: # Check if we even have the last update time + status_msg += f" — Data as of {self._db._data_update_time.strftime("%d %b %Y")}" return template.render(status=status_msg, lang=lang, db=self._db, cfg=self._config) diff --git a/combogen/DrugDatabase.py b/combogen/DrugDatabase.py index d37e784..944b8ec 100644 --- a/combogen/DrugDatabase.py +++ b/combogen/DrugDatabase.py @@ -1,11 +1,27 @@ import requests -import json from collections import OrderedDict +from datetime import datetime class DrugDatabase(object): def __init__(self, config): self._combos = requests.get(config.url).json() + + # Uses the config.url to find the last repository commit to use it's time + # as the last update of the combo data + # is Ellipsis if the config.url is not a GitHub raw link + # the result is used in the result page footer + try: + self._data_update_time = datetime.fromisoformat(requests.get( + f"https://api.github.com/repos/{'/'.join(config.url.split('/')[3:5])}/commits?path=drugs.json&page=1&per_page=1" + ).json()[0]['commit']['committer']['date']) + except requests.RequestException as e: + print("""Failed to get time of the last source data update + The source URL (in config.url) is most likely not a file link stored on GitHub. + You can safely ignore this error or read the README for troubleshooting information. + Error message: """, e) + self._data_update_time = Ellipsis + self._config = config self._drug_groups = [] self.load_groups() diff --git a/combogen/templates/combo-chart-full.html b/combogen/templates/combo-chart-full.html index dca4e3b..21f728c 100644 --- a/combogen/templates/combo-chart-full.html +++ b/combogen/templates/combo-chart-full.html @@ -3,7 +3,7 @@ {{ title }} - + @@ -31,4 +31,4 @@

{{ cfg.translate(lang, "support") }}

- \ No newline at end of file + diff --git a/combogen/templates/legend.html b/combogen/templates/legend.html index 11ca6d3..0204491 100644 --- a/combogen/templates/legend.html +++ b/combogen/templates/legend.html @@ -13,4 +13,7 @@
{{ fa_label("Low Risk & Decrease") }}
-{{ status }} +
{{ status }} +
Work licence — CC BY-NC-SA 4.0 (creativecommons.org/licenses/by-nc-sa/4.0) +
Source available — github.com/TripSit/combogen +
diff --git a/config.json b/config.json index a675766..d8bc003 100644 --- a/config.json +++ b/config.json @@ -1,5 +1,5 @@ { - "url": "https://github.com/TripSit/drugs/blob/main/combos.json", + "url": "https://raw.githubusercontent.com/TripSit/drugs/refs/heads/main/combos.json", "version": "5.0.0", "tableOrder": [ [ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b93a7b1 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +jinja2 +requests diff --git a/resources/css/style.css b/resources/css/style.css index 2241e42..bc97054 100644 --- a/resources/css/style.css +++ b/resources/css/style.css @@ -260,4 +260,4 @@ footer #disclaimer { /* right: 8%; */ top: 0; font-size: 24pt; -} \ No newline at end of file +}