-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.py
executable file
·48 lines (35 loc) · 1.57 KB
/
main.py
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
#!/usr/bin/env python3
"""
Python command line tool for taking command of your crypto coins
Command line tool to fetch and display information from the coinmarketcap API
"""
import argparse
import os
import time
from modules import API
from modules import Displayer
__author__ = "Jasper Haasdijk"
__version__ = "1.0.0"
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--version", action="version", version=__version__)
parser.add_argument("-c", help="convert to your preferred fiat currency", choices=API.currencies, default="USD",
metavar="currency")
parser.add_argument("-f", help="only display your desired coins", default=None, metavar="list")
parser.add_argument("-r", help="automatically refresh information every <rate> seconds", default=0, metavar="rate")
parser.add_argument("-t", help="display the first <top> currencies", default=10, metavar="top")
args = parser.parse_args()
if args.f: # if we are focusing on a specific coin, we want to look further than the top 10 listings
args.t = 0
default_iteration(args.t, args.c, args.f, args.r)
def default_iteration(top, convert, find, refresh):
response = API.get_response(top, convert)
data = API.parse_response(response)
output = Displayer.display_information(data, convert.lower(), find)
print(output)
while refresh:
os.system('cls' if os.name == 'nt' else 'clear')
default_iteration(top, convert, find, refresh=False)
time.sleep(float(refresh))
if __name__ == '__main__':
parse_args()