-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmain_cli.py
More file actions
executable file
·98 lines (79 loc) · 2.54 KB
/
main_cli.py
File metadata and controls
executable file
·98 lines (79 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import click
import os
import sys
from .discogs import Release, Artist, Label, Search, Master
import requests
requests.packages.urllib3.disable_warnings()
@click.group()
def cli():
pass
@cli.command('label')
@click.argument('label_id')
def label(label_id):
"""Retrieve record label data and its associated releases."""
r = Label(label_id)
try:
r.show()
except IOError as e:
pass
except Exception as e:
click.secho('Unable to fetch label id: {label_id} ({e})'.format(
label_id=label_id, e=e), fg='red')
@cli.command('release')
@click.argument('release_id')
@click.option('--exclude', default="None")
@click.option('--include', default="All")
def release(release_id,exclude,include):
"""Retrieve a single release from the discogs database."""
r = Release(release_id,exclude=exclude,include=include)
try:
r.show()
except Exception as e:
click.secho('Unable to fetch release id: {release_id} ({e})'.format(
release_id=release_id, e=e), fg='red')
@cli.command('artist')
@click.argument('artist_id')
def artist(artist_id):
"""Retrieve artist information and their associated releases."""
r = Artist(artist_id)
try:
r.show()
except IOError as e:
pass
except Exception as e:
click.secho('Unable to fetch artist id: {artist_id} ({e})'.format(
artist_id=artist_id, e=e), fg='red')
@cli.command('master')
@click.argument('master_id')
def artist(master_id):
"""Retrieve master release information and their associated versions."""
r = Master(master_id)
try:
r.show()
except IOError as e:
pass
except Exception as e:
click.secho('Unable to fetch master id: {master_id} ({e})'.format(
master_id=master_id, e=e), fg='red')
@cli.command('search')
@click.argument('query')
@click.option('--lookup', default='release')
def search(query, lookup):
"""Search for Discogs artist, release, label information."""
token = os.environ.get('TOKEN')
if not token:
click.secho('Unable to read your user_token. try export TOKEN=your_discogs_token_here',
fg='red')
else:
s = Search(query, q_type=lookup, user_token=token)
try:
s.show()
except IOError as e:
pass
except Exception as e:
click.secho('Unable to perform a {t} search for {q} ({e})'.format(
t=lookup, q=query, e=e), fg='red')
if __name__ == '__main__':
cli()