Skip to content

Commit

Permalink
refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
jhsuss committed Oct 21, 2024
0 parents commit 334b03c
Show file tree
Hide file tree
Showing 13 changed files with 679 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .Rhistory
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
n
n
library(tidyverse)
read_csv("https://raw.githubusercontent.com/ft-interactive/fetch_superforecasts/refs/heads/main/data/superforecasts.csv?token=GHSAT0AAAAAACRBXEEMQZI52AEUFBKYBPLIZYCVSRQ")
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @ft-interactive/visual-data-journalism-admins
38 changes: 38 additions & 0 deletions .github/workflows/run-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: run-pipeline

on:
push:
schedule:
- cron: '5 12 * * *'

jobs:
pipeline:
runs-on: ubuntu-latest

permissions:
# Allow the action to update the repo
contents: write

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.x
cache: pipenv

- name: Install pipenv
run: pip install pipenv

- name: Install dependencies
run: pipenv install --ignore-pipfile

- name: Run python code
env: # Set the secret as an input
FUTURE_FIRST: ${{ secrets.FUTURE_FIRST }}
# FIRST_NAME: Joel
# LAST_NAME: Suss
run: pipenv run start

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Data update
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store
.venv
.env
.Rproj.user
16 changes: 16 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
requests = "*"
pandas = "*"

[dev-packages]

[requires]
python_version = "3"

[scripts]
start = "python3 run.py"
289 changes: 289 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Retrieve latest superforecasts from FutureFirst (https://goodjudgment.io/futurefirst/index.php)
273 changes: 273 additions & 0 deletions data/superforecasts.csv

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions fetch_superforecasts.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: Sweave
LaTeX: pdfLaTeX
11 changes: 11 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pandas as pd
import json

from src.fetch import get_data
from os.path import abspath

data = get_data()

# Write string to CSV file
with open(abspath("./data/superforecasts.csv"), 'w') as f:
f.write(data)
Empty file added src/.gitkeep
Empty file.
20 changes: 20 additions & 0 deletions src/fetch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import requests
import os

def get_data():

# Retrieve the environment variable "key"
key = os.getenv("FUTURE_FIRST")

r = requests.get(
"https://goodjudgment.io/futurefirst/api/fcsv",
headers = {"Authorization": "Bearer " + key}
)

data = r.json()["data"]
print(f"Loaded {len(data)} rows of CSV from the API")
return data




9 changes: 9 additions & 0 deletions src/save.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import csv

def write_data(path, data):
with open(path, 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=data[0].keys())
writer.writeheader()
for row in data:
writer.writerow(row)
print(f"Wrote {len(data)} rows to {path}")

0 comments on commit 334b03c

Please sign in to comment.