Movatterモバイル変換


[0]ホーム

URL:


Skip to content
Search Gists
Sign in Sign up

Instantly share code, notes, and snippets.

View pybites's full-sized avatar

Pybites pybites

Humanizing Python Development
View GitHub Profile
#!/bin/bash
# brew or apt-get install gh jq fzf
CACHE_FILE=~/.gh_repos.json
CACHE_DURATION=$((60*60*24*3))# 3 days in seconds
if [!-f"$CACHE_FILE" ]|| [$(( $(date+%s)- $(stat-c%Y "$CACHE_FILE")))-ge$CACHE_DURATION ];then
echo"Refreshing cache..."
gh api user/repos --paginate>"$CACHE_FILE"
fi
fromtypingimportProtocol
classPybitesSearchProtocol(Protocol):
defmatch_content(self,search:str)->list[str]:
"""Implement in subclass to search Pybites content"""
...
classCompleteSearch:
defmatch_content(self,search:str)->list[str]:
# Implementation of search method
# prior step done:
# python manage.py dumpdata auth.User --output=users.json --format=json
fromcollectionsimportCounter
importjson
importplotextasplt
defaggregate_users_by_year_month(filename="users.json"):
cnt=Counter()
fromdjango.core.management.baseimportBaseCommand
importfeedparser
fromdjango.db.utilsimportIntegrityError
fromblog.modelsimportArticle
FEED_URL="https://pybit.es/feed/"
classCommand(BaseCommand):
>>>defgen():
...yieldfrom [1,2,3]
...
>>>g=gen()
>>>foriing:print(i)
...
1
2
3
# generator exhausted:
repos:
-repo:https://github.com/pre-commit/pre-commit-hooks
rev:v4.0.1
hooks:
-id:check-yaml
-id:end-of-file-fixer
-id:trailing-whitespace
-id:debug-statements
-repo:https://github.com/pycqa/flake8
importcProfile
fromfunctoolsimportwraps
frompstatsimportStats,SortKey
fromtimeimporttime
deftiming(f):
"""A simple timer decorator"""
@wraps(f)
defwrapper(*args,**kwargs):
"""Script to retrieve new titles from O'Reilly Media (formerly Safari Books Online)"""
fromcollectionsimportnamedtuple
frompathlibimportPath
fromdatetimeimportdatetime,timedelta
fromurllib.requestimporturlretrieve
fromxml.etree.ElementTreeimportparse
RSS_FEED="https://www.oreilly.com/feeds/recently-added.rss"
NOW=datetime.now()
DT_FMT="%a, %d %b %Y %H:%M:%S"
importasyncio
importos
importaiofiles
importaiohttp
# saved links from https://pybit.es/archives in urls
URLS= [u.rstrip()foruinopen('urls','r').readlines()]
asyncdeffetch(session,url):
fromimportlibimportimport_module
fromkeywordimportkwlist
importbuiltins
fromtypingimportDict,List
scores= {
"builtin":1,
"keyword":2,
"module":3,
}
NewerOlder

[8]ページ先頭

©2009-2025 Movatter.jp