Skip to content

Commit

Permalink
Creating objects and parsing with dummy data file
Browse files Browse the repository at this point in the history
  • Loading branch information
Tchekda committed Mar 15, 2019
1 parent 0c31279 commit a343d8f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 6 deletions.
10 changes: 4 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,10 @@ venv.bak/
# mypy
.mypy_cache/

\.idea/
.idea/

dummy\.txt
dummy.txt

run\.py
run.py

whazzup\.1\.txt

whazzup\.2\.txt
whazzup.*
10 changes: 10 additions & 0 deletions ivao/Client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Client:

def __init__(self, callsign, vid, client_type, frequency=None):
self.callsign = callsign
self.vid = vid
self.client_type = client_type
self.frequency = frequency

def __str__(self):
return "{0} as {1} with {2} callsign".format(self.vid, self.client_type, self.callsign)
19 changes: 19 additions & 0 deletions ivao/Parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from .Client import Client


class Parser:

def __init__(self):
with open('whazzup.2.txt') as file:
self.content = file.read()
self.clients = self.content.split('!CLIENTS\n')[1].split('!AIRPORTS')[0].split('\n')[:-1]

def get_raw_data(self):
return self.content

def get_clients_object(self):
users = []
for client in self.clients:
data = client.split(':')
users.append(Client(callsign=data[0], vid=data[1], client_type=data[3], frequency=data[4]))
return users
23 changes: 23 additions & 0 deletions ivao/Server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from .Parser import Parser


class Server:
clients = []
controllers = []
pilots = []
folme = []

def __init__(self):
self.update_data()

def update_data(cls):
parser = Parser()
for client in parser.get_clients_object():
if client not in cls.clients:
cls.clients.append(client)
if client.client_type == "ATC":
cls.controllers.append(client)
elif client.client_type == "PILOT":
cls.pilots.append(client)
else:
cls.folme.append(client)
3 changes: 3 additions & 0 deletions ivao/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .Server import *
from .Parser import *
from .Client import *

0 comments on commit a343d8f

Please sign in to comment.