def prep(self, meta, pub_uri=None, venue_uri=None, contributors=[]): bib = {} doi = pull(meta, "DOI") bib["doi"] = doi if pub_uri is not None: bib["uri"] = pub_uri # pub type ptype = self.pub_types(meta) bib.update(ptype) # one to one mappings for k in ["title", "volume", "issue"]: bib[k] = pull(meta, k) bib["pages"] = pull(meta, "page") # author list bib["authors"] = self._author_list(meta) # contributors contrib = [] for ct in contributors: contrib.append(ct) bib["contributor"] = contrib # date date = self._pub_date(meta) try: bib["date"] = date except Exception, e: logging.warn("Can't create date for {0}.".format(doi)) logging.warn(e)
def prep(self, meta, pub_uri=None, venue_uri=None, contributors=[]): bib = {} doi = pull(meta, 'DOI') bib['doi'] = doi if pub_uri is not None: bib['uri'] = pub_uri #pub type ptype = self.pub_types(meta) bib.update(ptype) #one to one mappings for k in ['title', 'volume', 'issue']: bib[k] = pull(meta, k) bib['pages'] = pull(meta, 'page') #author list bib['authors'] = self._author_list(meta) #contributors contrib = [] for ct in contributors: contrib.append(ct) bib['contributor'] = contrib #date date = self._pub_date(meta) try: bib['date'] = date except Exception, e: logging.warn("Can't create date for {0}.".format(doi)) logging.warn(e)
def build_translation(apps, _pull=False): """ build frappe app's translation """ from utils import config config_apps = config.get("apps") update_bench = config.get("update_bench") release_bench = config.get("release_bench") release_bench_site = config.get("release_bench_site") update_bench_site = config.get("update_bench_site") commit_msg = config.get( "translation_commit_msg") or "[docs] Updated translation" base_branches = config.get("base_branch_mapper") or {} # import source messages exec_cmd( update_bench, ['bench --site {0} import-source-messages'.format(update_bench_site)]) # translate unstranslated messages exec_cmd(update_bench, [ 'bench --site {0} translate-untranslated-all'.format(update_bench_site) ]) # write csv exec_cmd(update_bench, [ 'bench --site {0} execute "translator.data.write_csv_for_all_languages"' .format(update_bench_site) ]) # download the translation csv to frappe/erpnext app exec_cmd(release_bench, ['bench download-translations']) branch = "translations-{0}".format(now_date(format='%Y.%m.%d')) try: for app in config_apps: path = os.path.join(release_bench, 'apps', app) if app not in apps: exec_cmd(path, ['git stash']) if not path: print "app is not installed" continue base_branch = base_branches.get(app, "develop") if _pull: pull(path, "upstream", base_branch) checkout(path, branch, create_new=True) args = [ '{branch}:{branch}'.format(branch=branch), ] push(app, path, branch, commit_msg) pull_request(app, commit_msg, branch, base=base_branch) checkout(path, base_branch, delete_branch_after_checkout=True, delete_branch=branch) except Exception as e: print e
def build_docs(apps, _pull=False): """ build frappe app's documentation """ from utils import config release_bench = config.get("release_bench") release_bench_site = config.get("release_bench_site") commit_msg = config.get("docs_commit_msg") target_app_mapper = config.get("docs_target_apps") base_branches = config.get("base_branch_mapper") or {} branch = "docs-{0}".format(now_date(format='%Y.%m.%d')) for app in apps: try: apps_path = os.path.join(release_bench, 'apps', app) if not apps_path: print "app is not installed" target = target_app_mapper.get(app, {}) target_app = target.get("app", None) owner = target.get("owner", None) if not target_app or not owner: print "target app mapping not available" target_app_path = os.path.join(release_bench, 'apps', target_app) if not target_app_path: print "app is not installed" if _pull: pull(apps_path, "upstream", base_branches.get(app, "develop")) pull(target_app_path, "upstream", base_branches.get(target_app, "master")) checkout(target_app_path, branch, create_new=True) # build docs exec_cmd(release_bench, \ ['bench --site {0} build-docs --target {1} {2}'.format(release_bench_site, target_app, app)]) push(app, target_app_path, branch, commit_msg, commit=True) pull_request(target_app, commit_msg, branch, base=base_branches.get(target_app, "master"), owner=owner) checkout(target_app_path, base_branches.get(target_app, "master"), delete_branch_after_checkout=False, delete_branch=branch) except Exception as e: print e
def get_all_teams(): """ """ data = utils.pull('https://api-football-v1.p.rapidapi.com/v2/teams/league/2790') teams = [i['name'] for i in data['api']['teams']] return teams
def pub_types(self, meta): d = {} ptype = pull(meta, "type") if ptype == u"journal-article": d["a"] = "bcite:Article" elif (ptype == u"Book") or (ptype == u"Monograph"): d["a"] = "bcite:Book" # add to bcite ontology elif ptype == u"proceedings-article": d["a"] = "bcite:ConferencePaper" else: d["a"] = "bcite:Citation" return d
def pub_types(self, meta): d = {} ptype = pull(meta, 'type') if ptype == u'journal-article': d['a'] = 'bcite:Article' elif (ptype == u'Book') or (ptype == u'Monograph'): d['a'] = 'bcite:Book' #add to bcite ontology elif ptype == u'proceedings-article': d['a'] = 'bcite:ConferencePaper' else: d['a'] = 'bcite:Citation' return d
def get_fixtures_text(round_number): ''' ''' round = 'Regular_Season_-_{}'.format(round_number) text = 'Fixtures:\n\n' data = utils.pull("https://api-football-v1.p.rapidapi.com/v2/fixtures/league/2790/{}".format(round)) raw_data = data['api']['fixtures'] for i in raw_data: text += '{} vs {}\n'.format(i['homeTeam']['team_name'],i['awayTeam']['team_name']) return text
def get_team_lists(round_number): """ """ round = 'Regular_Season_-_{}'.format(round_number) data = utils.pull("https://api-football-v1.p.rapidapi.com/v2/fixtures/league/2790/{}".format(round)) played, not_played = find_teams_that_played(data['api']['fixtures']) draws = find_draws(played) wins_and_loss = remove_draws(played, draws) wins, loss = find_winners_and_loosers(wins_and_loss) return wins, loss, draws, not_played, played
def fixture_request_text(name): ''' ''' round_number = utils.get_current_round() round = 'Regular_Season_-_{}'.format(round_number) text = 'Hi {}, the fixtures for Round {} are: \n\n'.format(name, round_number) data = utils.pull("https://api-football-v1.p.rapidapi.com/v2/fixtures/league/2790/{}".format(round)) raw_data = data['api']['fixtures'] for i in raw_data: text += '{} vs {}\n'.format(i['homeTeam']['team_name'],i['awayTeam']['team_name']) return text
def prep(self, meta, pub_uri=None, venue_uri=None, contributors=[]): """ Create JSON to pass to the context. """ bib = {} if pub_uri is not None: bib['uri'] = pub_uri #pub type ptype = self.pub_types(meta) bib.update(ptype) #One to one mappings for k in ['title', 'volume', 'issue', 'pages']: bib[k] = pull(meta, k) #For books, the title is in booktitle. if bib.get('title') is None: bib['title'] = pull(meta, 'booktitle') #Identifiers for aid in meta.get('articleids', []): value = pull(aid, 'value') id_type = aid.get('idtype') if id_type == 'pubmed': bib['pmid'] = value elif id_type == 'doi': bib['doi'] = value elif id_type == 'pmc': bib['pmcid'] = value #Handle author list authors = [] for au in meta.get('authors', []): authors.append(au['name']) bib['authors'] = u", ".join(authors) #contributors contrib = [] for ct in contributors: contrib.append(ct) bib['contributor'] = contrib bib['date'] = self.date(meta) #Get venues if there is one. venue = {} if venue_uri is not None: venue['uri'] = venue_uri venue['label'] = pull(meta, 'fulljournalname') venue['issn'] = pull(meta, 'issn') venue['eissn'] = pull(meta, 'essn') venue['a'] = "bcite:Venue" if (venue['label'] is not None): bib['venue'] = venue #Check for book book = pull(meta, 'booktitle') if book is not None and bib.get('title') is not None: bib['book'] = book #Check for urls url = pull(meta, 'availablefromurl') if url is not None: bib['url'] = url c = {} c.update(context.base) c.update(context.publication) bib['@context'] = c return bib
async def pull_api(srv: Server, req: Request) -> bool: return pull("/api")
async def pull_updater(srv: Server, req: Request) -> bool: return pull("/code")
async def pull_all(srv: Server, req: Request) -> Dict[str, bool]: return { "code": pull("/code"), "api": pull("/api") }
return web.Response() async def api_wh(req: web.Request) -> web.Response: await verify_github_request(req) print("API webhook fired") asyncio.create_task(update_apis()) return web.Response() if __name__ == "__main__": pull("/code") app = web.Application() with open(args.config_file, "r") as f: app["config"] = yaml.load(f, Loader=yaml.SafeLoader) app["args"] = args app.on_startup.append(on_startup) app.on_cleanup.append(on_cleanup) app.add_routes([web.post("/wh/github/updater", updater_wh)]) app.add_routes([web.post("/wh/github/api", api_wh)]) web.run_app(app, host=app["args"].host, port=app["args"].port)
class Publication(object): def __init__(self): pass def fetch(self, doi): raw = get_citeproc(doi) return raw def _author_list(self, meta): authors = [] for au in meta.get('author', []): astring = u"{0}, {1}".format(au.get('family'), au.get('given')) authors.append(astring) if authors == []: return None else: return u", ".join(authors) def _pub_date(self, meta): dval = meta.get('issued', {}) dparts = dval.get('date-parts') if dparts is None: return else: dgrp = dparts[0] try: year = int(dgrp[0]) except Exception: #Some DOIs don't have dates issued. #Set to 1900 so that we can track these down later. return date(year=1900, month=1, day=1) try: month = int(dgrp[1]) except IndexError: month = 1 return date(year=year, month=month, day=1) def pub_types(self, meta): d = {} ptype = pull(meta, 'type') if ptype == u'journal-article': d['a'] = 'bcite:Article' elif (ptype == u'Book') or (ptype == u'Monograph'): d['a'] = 'bcite:Book' #add to bcite ontology elif ptype == u'proceedings-article': d['a'] = 'bcite:ConferencePaper' else: d['a'] = 'bcite:Citation' return d def prep(self, meta, pub_uri=None, venue_uri=None, contributors=[]): bib = {} doi = pull(meta, 'DOI') bib['doi'] = doi if pub_uri is not None: bib['uri'] = pub_uri #pub type ptype = self.pub_types(meta) bib.update(ptype) #one to one mappings for k in ['title', 'volume', 'issue']: bib[k] = pull(meta, k) bib['pages'] = pull(meta, 'page') #author list bib['authors'] = self._author_list(meta) #contributors contrib = [] for ct in contributors: contrib.append(ct) bib['contributor'] = contrib #date date = self._pub_date(meta) try: bib['date'] = date except Exception, e: logging.warn("Can't create date for {0}.".format(doi)) logging.warn(e) #venue venue = {} if venue_uri is not None: venue['uri'] = venue_uri venue['label'] = pull(meta, 'container-title') venue['issn'] = pull(meta, 'ISSN') venue['isbn'] = pull(meta, 'ISBN') venue['a'] = 'bcite:Venue' bib['venue'] = venue bib['published_in'] = pull(meta, 'container-title') c = {} c.update(context.base) c.update(context.publication) bib['@context'] = c return bib