-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfpl_cli.py
executable file
·43 lines (36 loc) · 1.25 KB
/
fpl_cli.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
#!/usr/bin/env python3
#
# Command Line Script to print a live FPL table
#
# Usage: ./fpl_cli.py league_id
#
# Author: David Lillis (dave /at/ lill /dot /is)
#
from pykka_fpl import LeagueFetcher
from collections import OrderedDict
import pykka
import sys
class LeaguePrinter(pykka.ThreadingActor):
def __init__(self, league_id):
super(LeaguePrinter, self).__init__()
self.league_id = league_id
def on_start(self):
# create new actor instance to gather the data
self.league_fetcher = LeagueFetcher.start()
# request data about league_id
self.league_fetcher.tell({'league-id': self.league_id, 'reply-to': self.actor_ref })
def on_receive(self, message):
# league data (list of dicts)
league = message.get('league')
print('-' * len(message.get('league-name')))
print(message.get('league-name'))
print('-' * len(message.get('league-name')))
for t in league:
print('{} {} {} '.format(t.get_total_points(), t.get_points(), t.get_manager_name()))
self.stop()
if __name__ == '__main__':
if len(sys.argv) != 2:
print( 'FPL Live League\nUsage:\n{} league-id'.format(sys.argv[0]))
exit(0)
else:
actor_ref = LeaguePrinter.start(league_id=sys.argv[1])