-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjobcli.py
More file actions
executable file
·51 lines (43 loc) · 1.73 KB
/
jobcli.py
File metadata and controls
executable file
·51 lines (43 loc) · 1.73 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
import click
import requests
import sys
def validate_output(ctx, param, value):
o = value.lower()
if o == 'csv':
return 'text/csv; charset=utf8'
if o == 'json':
return 'application/json; charset=utf8'
else:
raise click.BadParameter('Output type must be CSV or JSON.')
CONTEXT_SETTINGS = dict(token_normalize_func=lambda x: x.lower())
@click.command(context_settings=CONTEXT_SETTINGS)
@click.option('--country', '-c', default ='US', help='iso-alpha2 country code'
, type=click.Choice(['US', 'DE']))
@click.option('--location', '-l', default ='', help='city')
@click.option('--jobtitle', '-j', default ='', help='job title')
@click.option('--skills', '-s', default ='', help='search terms')
@click.option('--firm', '-f', default ='', help='company name')
@click.option('--page', '-p', default = 1, help='search result page')
@click.option('--output', '-o', default ='csv', help='output format'
, type=click.Choice(['CSV', 'JSON'])
, callback=validate_output)
@click.version_option('0.1b2', '--version', '-v')
def cli(jobtitle, country, location, output, firm, skills, page):
"""JobCLI: Your Command Line Job Board"""
url = 'http://api.jobcli.com/rpc/ads'
headers = {'Accept': output}
payload = {
"country" : country
,"location" : location
,"company" : firm
,"jobtitle" : jobtitle
,"skills" : skills
,"page" : page
}
try:
r = requests.post(url, headers=headers, data=payload)
sys.stdout.write(r.text)
except:
raise click.ClickException('The JobCLI server could not be reached at this moment.')
if __name__ == '__main__':
cli()