-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script for copying over Possible Articles
- Loading branch information
Showing
6 changed files
with
120 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,19 @@ | ||
# roni | ||
# Roni | ||
A bunch of scripts for automating creation of the daily COVID-19 news Rona Report | ||
|
||
# Usage | ||
|
||
* Save any desired articles to Possible Articles with: | ||
`python save_article.py "New York Times" http://nyt.com/thearticle` | ||
|
||
* Copy all Possible Articles marked "Use" to Articles and delete possibles: | ||
`python copy_possible_articles.py` | ||
|
||
* Fetch daily stats from The Atlantic: | ||
`python parser.py` | ||
|
||
* Print out a test report to report.html: | ||
`python report.py` | ||
|
||
* Send out the report emails: | ||
`python report.py 1` |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
This file is for copying over articles from Possible Articles to Articles | ||
""" | ||
from __future__ import absolute_import | ||
|
||
import requests | ||
|
||
from airtable import Airtable | ||
from models.article import Article | ||
|
||
|
||
class Copy(object): | ||
def __init__(self): | ||
self.airtable = Airtable() | ||
|
||
def format_payload(self, thing): | ||
payload = {} | ||
payload["records"] = [{"fields": thing.format()}] | ||
payload["typecast"] = True | ||
return payload | ||
|
||
def get_possible_articles(self): | ||
params = {"filterByFormula": "AND(Use = 1)"} | ||
possible, _ = self.airtable.get_content( | ||
"Possible Articles", "Date", 0, params) | ||
|
||
return possible | ||
|
||
def headers(self, thing): | ||
return { | ||
"Authorization": "Bearer %s" % thing.config["key"], | ||
"Content-type": "application/json; charset=utf-8" | ||
} | ||
|
||
def delete_possible_article(self, article): | ||
res = requests.delete( | ||
self.possibles[0].alt_api_url + "/" + article.id, | ||
headers=self.headers(article) | ||
) | ||
print res.json() | ||
|
||
def copy_possible_article(self, thing): | ||
payload = self.format_payload(thing) | ||
res = requests.post( | ||
thing.api_url, | ||
json=payload, | ||
headers=self.headers(thing), | ||
) | ||
print res.json() | ||
|
||
|
||
class CopyPossibleArticle(Copy): | ||
def __init__(self): | ||
super(CopyPossibleArticle, self).__init__() | ||
self.possibles = [] | ||
|
||
def go(self): | ||
self.get_possibles() | ||
|
||
print "Copying" | ||
for p in self.possibles: | ||
self.copy_possible_article(p) | ||
|
||
print "Deleting" | ||
for p in self.possibles: | ||
self.delete_possible_article(p) | ||
|
||
def get_possibles(self): | ||
possible = self.get_possible_articles() | ||
for p in possible["records"]: | ||
params = p["fields"] | ||
params["id"] = p["id"] | ||
self.possibles.append(Article(params)) | ||
|
||
|
||
if __name__ == "__main__": | ||
s = CopyPossibleArticle() | ||
s.go() |
This file contains 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
This file contains 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
This file contains 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