Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for 2023 #45

Merged
merged 13 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*~
*.log
*.yaml

lib64
pip-selfcheck.json
Expand All @@ -9,6 +8,7 @@ throttle.ctrl
user-password.py
user-config.py
pyvenv.cfg
.env

__pycache__/
bin/
Expand Down
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ This bot adds initial information at the start of year for Wikimedia Sverige. It

# Installation
Install required libraries with pip:

`$ pip install -r requirements.txt`
```
sebastian-berlin-wmse marked this conversation as resolved.
Show resolved Hide resolved
pip install -r requirements.txt
```

# Configuration
A configuration file, `config.yaml` by default, is needed to run. `config.yaml.sample` has comments documenting the various parameters and can be used as a template.

Configure Pywikibot, following the instructions on https://www.mediawiki.org/wiki/Manual:Pywikibot/user-config.py.

To edit Phabricator, a Conduit API token is required. This can be generated in the user settings: `Settings` -> `Conduit API Tokens`.
To edit Phabricator, a Conduit API token is required. This can be generated in the user settings: `Settings` -> `Conduit API Tokens`. The API token is read from environment variable `PHAB_API_TOKEN` which can be specified in the file `.env`.

# Input Data
## Files
Expand All @@ -20,11 +21,15 @@ Two files are required to run the bot: one containing project information and on
Information about programs, strategies and goals are fetched from a table on a wikipage, such as [this one from 2019](https://se.wikimedia.org/w/index.php?title=Verksamhetsplan_2019/Tabell_%C3%B6ver_program,_strategi_och_m%C3%A5l&oldid=75471). The code for this is specific for this particular table and would need to be adapted if the same information is represented in another way. Note that some information is stored in HTML comments.

# Running
The bot is run with the command

$ ./project_start.py project-file goal-file

For flags, see command line help (`$ ./project_start.py --help`).
The bot is run with the command:
```
./project_start.py project-file [goal-file]
```

For flags, see command line help:
```
./project_start.py --help
```

## Logging
The most important log messages are written to standard out. If you want more detailed logging, see the log file *project-start.log*.
23 changes: 4 additions & 19 deletions config.yaml.wmse → config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ project_columns:
lead: Ansvarig
e_mail: Mejlprefix
project_number: Projektnummer
area: Program
program: Program
swedish_name: Svenskt projektnamn
english_name: Engelskt projektnamn
about_english: About the project
about_english: Mini-description of the project
about_swedish: Om projektet
project_start: Projektstart
project_end: Projektslut
Expand Down Expand Up @@ -46,8 +46,8 @@ wiki:
budget: budget
finansiär_2: funder_2
budget_2: budget_2
year_parameter: år
year_pages:
operational_plan: Verksamhetsplan_<YEAR>/Tabell_över_program,_strategi_och_mål
current_projects_template: Mall:Aktuella projekt <YEAR>
simple:
<YEAR>: Mall:Årsida
Expand All @@ -63,19 +63,6 @@ wiki:
projects:
title: Projekt <YEAR>
template: Mall:Årsida för projekt
program_overview:
colours:
- "#339966"
- "#006699"
- "#990000"
- "#FF8C00"
title: Verksamhetsplan <YEAR>/Måluppfyllnad/Programöversikt
templates:
page: Mall:Programöversikt
program: Mall:Programöversikt/Program
strategy: Mall:Programöversikt/Strategi
goal: Mall:Programöversikt/Mål
project: Mall:Programöversikt/Projekt
categories:
general: Föreningen <YEAR>
pages:
Expand All @@ -86,15 +73,13 @@ wiki:
Resor <YEAR>: Resor
Årsmöte <YEAR>: Årsmöte
Checklistor <YEAR>: Checklistor
lokal-profil marked this conversation as resolved.
Show resolved Hide resolved
Utbildning <YEAR>: Utbildning
Globala mätetal <YEAR>: Globala mätetal
volunteer_tasks:
title: Frivilliguppdrag <YEAR>
template: Mall:Frivilliguppdrag år
project_name_template: Mall:Projektnamn
project_number_template: Mall:Projektid
phab:
api_token: api-...
api_url: https://phabricator.wikimedia.org/api
parent_project_id: 2480
request_delay: 10
request_delay: 1
17 changes: 0 additions & 17 deletions config.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ wiki:
# put and the name of the template to use for the goals.
template_parameter: Template:Goals
year_pages:
# Page where the operational plan can be found.
operational_plan:
# Template where current projects are listed
current_projects_template:
# Map of pages that will be created by substituting
Expand All @@ -52,19 +50,6 @@ wiki:
projects:
title:
template:
# Parameters for program overview page.
program_overview:
# Colours to use in the program headers.
colours:
- #123456
title:
templates:
# Template that is substed to create the page.
page:
# Templates that are used by the page template. Maps
# parameter name in the page template to template
# name.
parameter: Template
# Year categories.
categories:
# This category is added to each category page.
Expand All @@ -85,8 +70,6 @@ wiki:
project_number_template:
# Parameters for Phabricator
phab:
# API-token for Conduit.
api_token: api-...
# URL to the API.
api_url: https://.../api
# Id of the project that created projects will be subprojects
Expand Down
8 changes: 6 additions & 2 deletions phab.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import logging
from time import sleep, time
import os

import requests
from dotenv import load_dotenv


class Phab:
Expand All @@ -23,6 +25,8 @@ def __init__(self, config, dry_run):
self._config = config
self._dry_run = dry_run
self._last_request_time = 0.0
load_dotenv()
self._api_token = os.getenv("PHAB_API_TOKEN")

def add_project(self, name, description):
"""Add project.
Expand Down Expand Up @@ -131,15 +135,15 @@ def _make_request(self, endpoint, parameters_dict):
parameters = self._to_phab_parameters(parameters_dict)
# Add placeholder API token to not reveal the real one in logs.
logged_parameters = parameters.copy()
logged_parameters["api.token"] = "api-..."
logged_parameters["api.token"] = "api-REDACTED"
logging.debug(
"POST to Phabricator API on {}/{}: {}".format(
self._config["api_url"],
endpoint,
logged_parameters
)
)
parameters["api.token"] = self._config["api_token"]
parameters["api.token"] = self._api_token
self._last_request_time = time()
response = requests.post(
"{}/{}".format(self._config["api_url"], endpoint),
Expand Down
3 changes: 2 additions & 1 deletion project_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ def process_project(project_information, project_columns):
wiki.add_project(
project_information[project_columns["project_number"]],
project_information[project_columns["swedish_name"]],
project_information[project_columns["english_name"]]
project_information[project_columns["english_name"]],
project_information[project_columns["program"]]
)


Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ pywikibot==8.1.2
pyyaml==6.0
mwparserfromhell==0.6.4
wikitables==0.5.5
python-dotenv==1.0.0
Loading