-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobservatory.py
More file actions
102 lines (99 loc) · 3.1 KB
/
observatory.py
File metadata and controls
102 lines (99 loc) · 3.1 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
99
100
101
102
import os
import sys
import time
import requests
if __name__ == '__main__':
if len(sys.argv) != 2:
sys.exit('Usage: {0} <conf.txt>'.format(sys.argv[0]))
try:
conf = open(sys.argv[1], "r")
except:
sys.exit('Unable to open: {}'.format(sys.argv[1]))
# Standard values:
url = "http://bzstats.strayer.de/stuff/LePoulpe303.php"
favorites=[]
friends=[]
Display=[]
count = 1
launch = 0
Friend=0
Server=0
AddToList=-1
# Reading and setting configs.
confval = conf.read()
for line in confval.splitlines():
if len(line) >= 7: # [S] Space Username or Server
if line[:5] == "[F] ":
friends.append(line[5:].lower())
if line[:5] == "[S] ":
favorites.append(line[5:].lower())
conf.close()
# Setting standard type
if len(favorites) >= 1:
count += 1
if len(friends) >= 1:
count += 1
if count == 3:
count = 4
# Main loop.
while True:
req = requests.get(url)
if req.status_code != 200:
print("ERROR in getting request.")
else:
resp = req.text
lines = resp.splitlines()
if len(resp) < 3:
print("===NO PLAYERS FOUND===")
elif count == 1:
for line in lines:
data = line.split("\t")
print("{} :: {} :: On :: {}".format(data[0], data[1], data[2]))
else:
for con in range(count):
launch = con
for line in lines:
AddToList=-1
data = line.split("\t")
Friend=0
Server=0
if len(friends) >= 1:
for fri in friends:
if fri == data[0].lower():
Friend=1
if len(favorites) >= 1:
for fav in favorites:
if fav == data[2].lower():
Server=1
# Probably the values should be stored in an array or something to lookup.
if Friend == 0 and Server == 0:
if con == 1 and count == 2 or con == 3 and count == 4:
AddToList=3
else:
if Friend == 1:
if Server == 1:# Friend & Server
AddToList = 0
else:
if con == 0 and count == 2 or con == 1 and count == 4:# Friend
AddToList=1
else: # Server
if con == 0 and count == 2 or con == 2 and count == 4:
AddToList=2
if AddToList != -1:
if launch == con:
if AddToList == 0:
Display.append("===Friends on Favorite Servers:===")
if AddToList == 1:
Display.append("===Friends found on Servers:===")
if AddToList == 2:
Display.append("===Favorite Servers:===")
if AddToList == 3:
if len(Display) >= 1:
Display.append("===End of favorites/friends===")
launch += 1
Display.append(" {} ::: On :: {} As {} team".format(data[0], data[2], data[1]))
for display in Display:
print(display)
Display.clear()
time.sleep(150)
os.system("clear")