Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Junk, mostly. Some salvagable
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Oct 22, 2016
1 parent ffdbaa7 commit 4d92a22
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 1 deletion.
61 changes: 61 additions & 0 deletions gratipay/chomp/__init__.py
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)
12 changes: 12 additions & 0 deletions gratipay/models/package.py
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,))
4 changes: 4 additions & 0 deletions gratipay/utils/markdown.py
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()
4 changes: 3 additions & 1 deletion gratipay/wireup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from gratipay.elsewhere.openstreetmap import OpenStreetMap
from gratipay.elsewhere.twitter import Twitter
from gratipay.elsewhere.venmo import Venmo
from gratipay.models.npm_package import Package
from gratipay.models.account_elsewhere import AccountElsewhere
from gratipay.models.community import Community
from gratipay.models.country import Country
Expand Down Expand Up @@ -56,7 +57,8 @@ def db(env):
maxconn = env.database_maxconn
db = GratipayDB(dburl, maxconn=maxconn)

for model in (AccountElsewhere, Community, Country, ExchangeRoute, Participant, Team):
models = (AccountElsewhere, Community, Country, ExchangeRoute, Participant, Team, Package)
for model in models:
db.register_model(model)
gratipay.billing.payday.Payday.db = db

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
, entry_points = { 'console_scripts'
: [ 'payday=gratipay.cli:payday'
, 'fake_data=gratipay.utils.fake_data:main'
, 'chomp=gratipay.chomp:main'
]
}
)
26 changes: 26 additions & 0 deletions sql/branch.sql
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;

0 comments on commit 4d92a22

Please sign in to comment.