Skip to content

Commit c946719

Browse files
committed
Merge branch 'main' into chore/upgrade_pants_2.23
2 parents 627c3dc + 4b262cb commit c946719

21 files changed

+542
-20
lines changed

Diff for: .flake8

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[flake8]
22
max-line-length = 88
3-
extend-ignore = E203,E701
3+
extend-ignore = E203,E701

Diff for: .github/workflows/twoops-tracker-cd.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
docker push ${{ env.IMAGE_NAME }}:${{ env.VERSION }}
7272
7373
- name: Push to Dokku
74-
uses: dokku/github-action@v1.4.0
74+
uses: dokku/github-action@v1.6.1
7575
with:
7676
branch: ${{ env.DOKKU_REMOTE_BRANCH }}
7777
git_push_flags: ${{ env.GIT_PUSH_FLAGS }}

Diff for: .gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,6 @@ cython_debug/
165165
### Pyenv ###
166166

167167
.python-version
168-
168+
# Custom gitignore
169+
*.db
169170
# End of custom ignore

Diff for: 3rdparty/py/requirements-all.txt

+19-16
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1-
boto3==1.34.39
2-
celery==5.3.6
3-
dj-rest-auth==5.0.2
4-
# Match dj-rest-auth[with_social]==5.0.2
5-
django-allauth>=0.56.0,<0.58.0
1+
boto3==1.35.64
2+
celery==5.4.0
3+
dj-rest-auth==5.1.0
4+
# Match dj-rest-auth[with_social]==5.1.0
5+
django-allauth>=0.56.0,<0.62.0
66
Django==3.2.23
7-
django-cors-headers==4.3.1
8-
django-storages==1.14.2
9-
djangorestframework==3.14.0
7+
django-cors-headers==4.5.0
8+
django-storages==1.14.4
9+
djangorestframework==3.15.1
1010
djangorestframework-simplejwt==5.3.1
1111
environs[django]==10.3.0
12-
google-api-python-client==2.117.0
12+
google-api-python-client==2.153.0
1313
google-auth==2.36.0
1414
google-auth-httplib2==0.2.0
15-
google-auth-oauthlib==1.2.0
16-
greenlet==3.0.3
17-
gunicorn[gevent, setproctitle]==21.2.0
18-
redis==5.0.1
19-
requests==2.31.0
20-
sentry-sdk==1.40.3
21-
tablib[xlsx]==3.5.0
15+
google-auth-oauthlib==1.2.1
16+
greenlet==3.1.1
17+
gunicorn[gevent, setproctitle]==23.0.0
18+
html2text==2024.2.26
19+
lxml==5.3.0
20+
redis==5.2.0
21+
requests==2.32.3
22+
sentry-sdk==2.18.0
23+
tablib[xlsx]==3.7.0
24+
trafilatura==1.12.2
2225
tweepy==4.14.0

Diff for: 3rdparty/py/requirements-dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
-r requirements-all.txt
22

3-
psycopg2-binary==2.9.9
3+
psycopg2-binary==2.9.10

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
| Name | Description |
66
| ----------------------------------------------- | -------------------------------------------- |
7+
| [**PesaCheck Meedan Bridge**](./pesacheck_meedan_bridge/README.md) | A simple service to move articles between the two platforms |
78
| [**TwoopsTracker**](./twoops_tracker/README.md) | A Twitter-based disinformation tracking tool |
89

910
## Packages

Diff for: compose.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,16 @@ services:
4747
depends_on:
4848
- twoopstracker_app
4949

50+
pesacheck_meedan_bridge:
51+
image: codeforafrica/pesacheck_meedan_bridge:latest
52+
command: ["tail", "-f", "/dev/null"]
53+
volumes:
54+
- pesacheck-data:/app/database
55+
env_file:
56+
- ./pesacheck_meedan_bridge/.env
57+
5058
volumes:
5159
app-media:
5260
app-staticfiles:
5361
db-data:
62+
pesacheck-data:

Diff for: pants.toml

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ root_patterns = [
3838
"/twoops_tracker/docker",
3939
"/twoops_tracker/py",
4040
"/pants-plugins",
41+
"/pesacheck_meedan_bridge/py",
42+
"/pesacheck_meedan_bridge/docker",
4143
]
4244

4345
[python]

Diff for: pesacheck_meedan_bridge/.env.example

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
PESACHECK_URL=https://pesacheck.org/feed
2+
PESACHECK_RSS2JSON_API_KEY=
3+
PESACHECK_CHECK_URL=https://check-api.checkmedia.org/api/graphql
4+
PESACHECK_CHECK_TOKEN=
5+
PESACHECK_CHECK_WORKSPACE_SLUG=pesacheck-tipline-sandbox
6+
PESACHECK_SENTRY_DSN=
7+
PESACHECK_SENTRY_TRACES_SAMPLE_RATE=1.0
8+
PESACHECK_SENTRY_ENVIRONMENT=local

Diff for: pesacheck_meedan_bridge/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# PesaCheck Meedan Bridge
2+
3+
A simple service to pull articles from PesaCheck and post them to Meedan Check

Diff for: pesacheck_meedan_bridge/docker/BUILD

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
docker_image(
2+
name="pesacheck-deps",
3+
image_tags=["deps"],
4+
build_platform=["linux/amd64"],
5+
registries=["pesacheck_meedan_bridge"],
6+
repository="app",
7+
skip_push=True,
8+
source="Dockerfile.deps",
9+
)
10+
11+
file(name="app.json", source="app.json")
12+
13+
docker_image(
14+
name="pesacheck-srcs",
15+
image_tags=["srcs"],
16+
build_platform=["linux/amd64"],
17+
registries=["pesacheck_meedan_bridge"],
18+
repository="app",
19+
skip_push=True,
20+
source="Dockerfile.srcs",
21+
)
22+
23+
docker_image(
24+
name="pesacheck_meedan_bridge",
25+
build_platform=["linux/amd64"],
26+
dependencies=[":pesacheck-srcs", ":pesacheck-deps", ":app.json"],
27+
image_tags=[
28+
"{build_args.VERSION}",
29+
"latest",
30+
],
31+
source="Dockerfile",
32+
)

Diff for: pesacheck_meedan_bridge/docker/Dockerfile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM python:3.11-slim-bullseye AS python-base
2+
FROM pesacheck_meedan_bridge/app:deps AS app-deps
3+
FROM pesacheck_meedan_bridge/app:srcs AS app-srcs
4+
FROM python-base AS python-app
5+
6+
WORKDIR /app
7+
COPY pesacheck_meedan_bridge/docker/app.json ./
8+
COPY --from=app-deps /app ./
9+
COPY --from=app-srcs /app ./
10+
11+
CMD ["tail", "-f", "/dev/null"]

Diff for: pesacheck_meedan_bridge/docker/Dockerfile.deps

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM python:3.11-slim-bookworm
2+
3+
COPY pesacheck_meedan_bridge.py/pesacheck-deps@environment=linux.pex /pesacheck-deps.pex
4+
RUN PEX_TOOLS=1 python /pesacheck-deps.pex venv --scope=deps --compile /app

Diff for: pesacheck_meedan_bridge/docker/Dockerfile.srcs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM python:3.11-slim-bookworm
2+
3+
COPY pesacheck_meedan_bridge.py/pesacheck-srcs@environment=linux.pex /pesacheck-srcs.pex
4+
RUN PEX_TOOLS=1 python /pesacheck-srcs.pex venv --scope=srcs --compile /app

Diff for: pesacheck_meedan_bridge/docker/app.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "pesacheck_meedan_bridge",
3+
"cron": [
4+
{
5+
"command": "./pex",
6+
"schedule": "@daily"
7+
}
8+
]
9+
}

Diff for: pesacheck_meedan_bridge/py/BUILD

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
python_sources(
2+
name="lib",
3+
dependencies=[
4+
"3rdparty/py:requirements-all#lxml",
5+
"3rdparty/py:requirements-all#requests",
6+
"3rdparty/py:requirements-all#sentry-sdk",
7+
"3rdparty/py:requirements-all#environs",
8+
],
9+
)
10+
11+
pex_binary(
12+
name="pesacheck-deps",
13+
environment=parametrize("__local__", "linux"),
14+
dependencies=[
15+
":lib",
16+
],
17+
entry_point="main.py",
18+
include_sources=False,
19+
include_tools=True,
20+
layout="packed",
21+
)
22+
23+
pex_binary(
24+
name="pesacheck-srcs",
25+
environment=parametrize("__local__", "linux"),
26+
dependencies=[
27+
":lib",
28+
],
29+
entry_point="main.py",
30+
include_requirements=False,
31+
include_tools=True,
32+
layout="packed",
33+
)
34+
35+
36+
pex_binary(
37+
name="pesacheck_meedan_bridge",
38+
dependencies=[
39+
":lib",
40+
],
41+
entry_point="main.py",
42+
)

Diff for: pesacheck_meedan_bridge/py/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.1.12

Diff for: pesacheck_meedan_bridge/py/check_api.py

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import json
2+
3+
import requests
4+
import settings
5+
6+
7+
def create_mutation_query(
8+
media_type="Blank",
9+
channel=None,
10+
set_tags=[],
11+
set_status="",
12+
set_claim_description="",
13+
title="",
14+
summary="",
15+
url="",
16+
language="",
17+
publish_report=False,
18+
):
19+
mutation_query = f"""
20+
mutation create {{
21+
createProjectMedia(input: {{
22+
media_type: "{media_type}",
23+
channel: {{ main: {channel} }},
24+
set_tags: {json.dumps(set_tags)},
25+
set_status: "{set_status}",
26+
set_claim_description: \"\"\"{set_claim_description}\"\"\",
27+
set_fact_check: {{
28+
title: \"\"\"{title}\"\"\",
29+
summary: \"\"\"{summary}\"\"\",
30+
url: "{url}",
31+
language: "{language}",
32+
publish_report: {str(publish_report).lower()}
33+
}}
34+
}}) {{
35+
project_media {{
36+
id
37+
full_url
38+
claim_description {{
39+
fact_check {{
40+
id
41+
}}
42+
}}
43+
}}
44+
}}
45+
}}
46+
"""
47+
48+
return mutation_query
49+
50+
51+
def delete_mutation_query(id):
52+
mutation_query = f"""
53+
mutation {{
54+
destroyFactCheck(input: {{
55+
id: "{id}"
56+
}}) {{ deletedId }}
57+
}}
58+
"""
59+
return mutation_query
60+
61+
62+
def post_to_check(data):
63+
query = create_mutation_query(**data)
64+
headers = {
65+
"Content-Type": "application/json",
66+
"X-Check-Token": settings.PESACHECK_CHECK_TOKEN,
67+
"X-Check-Team": settings.PESACHECK_CHECK_WORKSPACE_SLUG,
68+
}
69+
body = dict(query=query)
70+
url = settings.PESACHECK_CHECK_URL
71+
response = requests.post(url, headers=headers, json=body, timeout=60)
72+
res = response.json()
73+
if response.status_code == 200 and res.get("data"):
74+
return res
75+
raise Exception(response.text)

0 commit comments

Comments
 (0)