Skip to content

Commit 47f1b1e

Browse files
committed
Initial commit - core code
0 parents  commit 47f1b1e

3 files changed

Lines changed: 273 additions & 0 deletions

File tree

.gitignore

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
2+
# Created by https://www.gitignore.io/api/vim,macos,python,windows
3+
# Edit at https://www.gitignore.io/?templates=vim,macos,python,windows
4+
5+
### macOS ###
6+
# General
7+
.DS_Store
8+
.AppleDouble
9+
.LSOverride
10+
11+
# Icon must end with two \r
12+
Icon
13+
14+
# Thumbnails
15+
._*
16+
17+
# Files that might appear in the root of a volume
18+
.DocumentRevisions-V100
19+
.fseventsd
20+
.Spotlight-V100
21+
.TemporaryItems
22+
.Trashes
23+
.VolumeIcon.icns
24+
.com.apple.timemachine.donotpresent
25+
26+
# Directories potentially created on remote AFP share
27+
.AppleDB
28+
.AppleDesktop
29+
Network Trash Folder
30+
Temporary Items
31+
.apdisk
32+
33+
### Python ###
34+
# Byte-compiled / optimized / DLL files
35+
__pycache__/
36+
*.py[cod]
37+
*$py.class
38+
39+
# C extensions
40+
*.so
41+
42+
# Distribution / packaging
43+
.Python
44+
build/
45+
develop-eggs/
46+
dist/
47+
downloads/
48+
eggs/
49+
.eggs/
50+
lib/
51+
lib64/
52+
parts/
53+
sdist/
54+
var/
55+
wheels/
56+
pip-wheel-metadata/
57+
share/python-wheels/
58+
*.egg-info/
59+
.installed.cfg
60+
*.egg
61+
MANIFEST
62+
63+
# PyInstaller
64+
# Usually these files are written by a python script from a template
65+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
66+
*.manifest
67+
*.spec
68+
69+
# Installer logs
70+
pip-log.txt
71+
pip-delete-this-directory.txt
72+
73+
# Unit test / coverage reports
74+
htmlcov/
75+
.tox/
76+
.nox/
77+
.coverage
78+
.coverage.*
79+
.cache
80+
nosetests.xml
81+
coverage.xml
82+
*.cover
83+
.hypothesis/
84+
.pytest_cache/
85+
86+
# Translations
87+
*.mo
88+
*.pot
89+
90+
# Django stuff:
91+
*.log
92+
local_settings.py
93+
db.sqlite3
94+
95+
# Flask stuff:
96+
instance/
97+
.webassets-cache
98+
99+
# Scrapy stuff:
100+
.scrapy
101+
102+
# Sphinx documentation
103+
docs/_build/
104+
105+
# PyBuilder
106+
target/
107+
108+
# Jupyter Notebook
109+
.ipynb_checkpoints
110+
111+
# IPython
112+
profile_default/
113+
ipython_config.py
114+
115+
# pyenv
116+
.python-version
117+
118+
# pipenv
119+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
120+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
121+
# having no cross-platform support, pipenv may install dependencies that don’t work, or not
122+
# install all needed dependencies.
123+
#Pipfile.lock
124+
125+
# celery beat schedule file
126+
celerybeat-schedule
127+
128+
# SageMath parsed files
129+
*.sage.py
130+
131+
# Environments
132+
.env
133+
.venv
134+
env/
135+
venv/
136+
ENV/
137+
env.bak/
138+
venv.bak/
139+
140+
# Spyder project settings
141+
.spyderproject
142+
.spyproject
143+
144+
# Rope project settings
145+
.ropeproject
146+
147+
# mkdocs documentation
148+
/site
149+
150+
# mypy
151+
.mypy_cache/
152+
.dmypy.json
153+
dmypy.json
154+
155+
# Pyre type checker
156+
.pyre/
157+
158+
### Vim ###
159+
# Swap
160+
[._]*.s[a-v][a-z]
161+
[._]*.sw[a-p]
162+
[._]s[a-rt-v][a-z]
163+
[._]ss[a-gi-z]
164+
[._]sw[a-p]
165+
166+
# Session
167+
Session.vim
168+
169+
# Temporary
170+
.netrwhist
171+
*~
172+
# Auto-generated tag files
173+
tags
174+
# Persistent undo
175+
[._]*.un~
176+
177+
### Windows ###
178+
# Windows thumbnail cache files
179+
Thumbs.db
180+
ehthumbs.db
181+
ehthumbs_vista.db
182+
183+
# Dump file
184+
*.stackdump
185+
186+
# Folder config file
187+
[Dd]esktop.ini
188+
189+
# Recycle Bin used on file shares
190+
$RECYCLE.BIN/
191+
192+
# Windows Installer files
193+
*.cab
194+
*.msi
195+
*.msix
196+
*.msm
197+
*.msp
198+
199+
# Windows shortcuts
200+
*.lnk
201+
202+
# End of https://www.gitignore.io/api/vim,macos,python,windows

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Jamquery CLI
2+
3+
Command line interface for Jamquery.
4+
Pretty unstable for now.
5+
6+
This program is fully written in Python.

jamquery.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
Jamquery CLI - Easily add/manage links
3+
4+
Usage:
5+
jamquery (-t | -d | -n | -a) <keyword>
6+
jamquery add <tags> <name> <url>
7+
jamquery -h | --help
8+
jamquery --version
9+
10+
Arguments:
11+
keyword Searching keyword.
12+
tags Comma-separated list of tags. (e.g. python,testing)
13+
name Name of new jamquery. Put it in quotes if you want to include some spaces.
14+
url URL of new jamquery. No space is allowed.
15+
16+
Options:
17+
-h --help Show this screen.
18+
--version Show version.
19+
-t, --tag Search in tags.
20+
-d, --date Search in dates.
21+
-n, --name Search in names.
22+
-a, --all Search for all fields.
23+
"""
24+
from docopt import docopt, DocoptExit
25+
import requests
26+
27+
VERSION = "0.0.1"
28+
URL = "http://jamquery.turastory.com/api"
29+
30+
def search(keyword):
31+
r = requests.get(f"{URL}/name/{keyword}")
32+
if r.status_code == 200:
33+
jamqueries = r.json()
34+
for jamquery in jamqueries:
35+
print(f"{jamquery['name']} - {jamquery['content']}")
36+
else:
37+
print(f"Error: {r.text}")
38+
39+
def parse_tags(tags):
40+
return [n.strip().lower() for n in tags.split(',')]
41+
42+
def add(tag_list, name, url):
43+
post_data = {'tags': tag_list, 'name': name, 'url': url}
44+
r = requests.post(f"{URL}", json=post_data)
45+
if r.status_code == 200:
46+
print(f"Add jamquery success with id: {r.json()['id']}")
47+
else:
48+
print(f"Error: {r.text}")
49+
pass
50+
51+
if __name__ == "__main__":
52+
arguments = docopt(__doc__, version=VERSION)
53+
54+
if arguments['add']:
55+
tags = arguments['<tags>']
56+
name = arguments['<name>']
57+
url = arguments['<url>']
58+
if tags == None or name == None or url == None:
59+
print("Arguments are needed")
60+
else:
61+
add(parse_tags(tags), name, url)
62+
else:
63+
# TODO: various search for various options
64+
keyword = arguments['<keyword>']
65+
search(keyword)

0 commit comments

Comments
 (0)