This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ffdbaa7
commit 4d92a22
Showing
6 changed files
with
107 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
"""Process npm artifacts. | ||
The main function is exposed as a console script named `chomp` via setup.py. | ||
""" | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
import argparse | ||
import sys | ||
|
||
import requests | ||
from gratipay.utils import markdown | ||
|
||
|
||
def from_npm(package): | ||
"""Given an npm package dict, return a dict of info and a list of emails. | ||
""" | ||
out= {} | ||
out['name'] = package['name'] | ||
out['description'] = package['description'] | ||
out['long_description'] = markdown.marky(package['readme']) | ||
out['long_description_raw'] = package['readme'] | ||
out['long_description_type'] = 'x-text/marky-markdown' | ||
|
||
emails = [] | ||
for key in ('authors', 'maintainers'): | ||
for person in package.get(key, []): | ||
if type(person) is dict: | ||
email = person.get('email') | ||
if email: | ||
emails.append(email) | ||
|
||
return out, emails | ||
|
||
|
||
def process_catalog(catalog): | ||
SQL = '' | ||
return SQL | ||
|
||
|
||
def fetch_catalog(): | ||
r = requests.get('https://registry.npmjs.com/-/all') | ||
r.raise_for_status() | ||
return r.json() | ||
|
||
|
||
def update_database(SQL): | ||
pass | ||
|
||
|
||
def parse_args(argv): | ||
p = argparse.ArgumentParser() | ||
p.add_argument( 'if_modified_since' | ||
, help='a number of minutes in the past, past which we need new updates' | ||
) | ||
return p.parse_args(argv) | ||
|
||
|
||
def main(argv=sys.argv): | ||
ims = parse_args(argv[1:]).if_modified_since | ||
process_catalog(fetch_catalog(), ims) |
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,12 @@ | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from postgres import orm | ||
|
||
|
||
class Package(orm.Model): | ||
typ_name = 'packages'; | ||
|
||
@classmethod | ||
def from_platform_and_name(cls, platform, name): | ||
return cls.db.one("SELECT packages.*::packages from packages where " | ||
"platform=%s and name=%s;", (platform, name,)) |
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,9 +1,13 @@ | ||
from markupsafe import Markup | ||
import misaka as m # http://misaka.61924.nl/ | ||
import subprocess | ||
|
||
def render(markdown): | ||
return Markup(m.html( | ||
markdown, | ||
extensions=m.EXT_AUTOLINK | m.EXT_STRIKETHROUGH | m.EXT_NO_INTRA_EMPHASIS, | ||
render_flags=m.HTML_SKIP_HTML | m.HTML_TOC | m.HTML_SMARTYPANTS | m.HTML_SAFELINK | ||
)) | ||
|
||
def marky(markdown): | ||
return subprocess.call() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
BEGIN; | ||
|
||
CREATE TABLE package_managers | ||
( id bigserial PRIMARY KEY | ||
, name text NOT NULL UNIQUE | ||
); | ||
|
||
CREATE TABLE packages | ||
( id bigserial PRIMARY KEY | ||
, package_manager_id bigint NOT NULL | ||
, name text NOT NULL | ||
, description text NOT NULL DEFAULT '' | ||
, long_description text NOT NULL DEFAULT '' | ||
, long_description_raw text NOT NULL DEFAULT '' | ||
, long_description_type text NOT NULL DEFAULT '' | ||
, mtime timestamp with time zone NOT NULL | ||
, UNIQUE (package_manager_id, name) | ||
); | ||
|
||
CREATE TABLE package_emails | ||
( package_id bigint NOT NULL | ||
, email text NOT NULL | ||
, UNIQUE (package_id, email) | ||
) | ||
|
||
END; |