Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b57c6a3

Browse files
Day 23 - Creating a Command Line Tool
1 parent 8ad1d39 commit b57c6a3

File tree

9 files changed

+940
-0
lines changed

9 files changed

+940
-0
lines changed

‎tutorial-reference/Day 23/Command Line Tool.ipynb

Lines changed: 418 additions & 0 deletions
Large diffs are not rendered by default.

‎tutorial-reference/Day 23/Pipfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[[source]]
2+
name = "pypi"
3+
url = "https://pypi.org/simple"
4+
verify_ssl = true
5+
6+
[dev-packages]
7+
8+
[packages]
9+
jupyter = "*"
10+
11+
[requires]
12+
python_version = "3.8"

‎tutorial-reference/Day 23/Pipfile.lock

Lines changed: 418 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import argparse
2+
3+
def my_const_fun(*args, **kwargs):
4+
print('const', args, kwargs)
5+
6+
def my_default_fun(*args, **kwargs):
7+
print('default', args, kwargs)
8+
9+
if __name__== "__main__":
10+
parser = argparse.ArgumentParser()
11+
parser.add_argument("integers", type=int, nargs="+")
12+
parser.add_argument("--sum", dest='accumulate', action='store_const', const=sum, default=max)
13+
parser.add_argument("--math", dest='math_is_fun', action='store_const', const=my_const_fun, default=my_default_fun)
14+
args = parser.parse_args()
15+
print(args.accumulate(args.integers))
16+
# print(args.math_is_fun(args.integers))

‎tutorial-reference/Day 23/cli_fire.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import fire
2+
3+
def hello(name='World'):
4+
return f"Hello {name}"
5+
6+
if __name__ == '__main__':
7+
fire.Fire(hello)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from getpass import getpass
2+
import fire
3+
4+
def login(name=None):
5+
if name == None:
6+
name = input("What's your name?\n")
7+
pw = getpass("What's your password?\n")
8+
return name, pw
9+
10+
if __name__ == '__main__':
11+
fire.Fire(login)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import fire
2+
from getpass import getpass
3+
4+
5+
class Auth(object):
6+
def login(self, username = None):
7+
if username == None:
8+
username = input("Username: ")
9+
if username == None:
10+
print("A username is required")
11+
return
12+
pw = getpass("Password: ")
13+
return username, pw
14+
15+
def login(username = None):
16+
if username == None:
17+
username = input("Username: ")
18+
if username == None:
19+
print("A username is required")
20+
return
21+
pw = getpass("Password: ")
22+
return username, pw
23+
24+
25+
def scrape_tag(tag = "python", query_filter = "Votes", max_pages=50, pagesize=25):
26+
base_url = 'https://stackoverflow.com/questions/tagged/'
27+
datas = []
28+
for p in range(max_pages):
29+
page_num = p + 1
30+
url = f"{base_url}{tag}?tab={query_filter}&page={page_num}&pagesize={pagesize}"
31+
datas.append(url)
32+
return datas
33+
34+
class Pipeline(object):
35+
def __init__(self):
36+
self.scrape = scrape_tag
37+
self.auth = Auth()
38+
self.login = login
39+
40+
if __name__ == '__main__':
41+
fire.Fire(Pipeline)

‎tutorial-reference/Day 23/cli_sys.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sys
2+
3+
4+
if __name__== "__main__":
5+
try:
6+
name = sys.argv[1]
7+
except:
8+
name = input("What's your name?\n")
9+
from getpass import getpass
10+
pw = getpass("What's your password?\n")
11+
print(name, pw)

‎tutorial-reference/Day 23/raw_input.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
from getpass import getpass
3+
name = input("What's your name?\n")
4+
pw = getpass("What's your password?\n")
5+
6+
print(name, pw)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /