Skip to content

Commit

Permalink
Main Files
Browse files Browse the repository at this point in the history
  • Loading branch information
MordantArc authored Oct 28, 2022
1 parent 6e11a86 commit dfa48ea
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
39 changes: 39 additions & 0 deletions ccvaClasses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import csv
import time

curDT = (str(round(time.time_ns())))

curfile = "./data/datafile"+curDT+".csv"

class CurCSV:

This comment has been minimized.

Copy link
@MordantArc

MordantArc Oct 28, 2022

Author Owner

This wont be the only class by a long shot, but it does give a good idea for my plan. A class for the SimConnect api for example. Then call it with args about what flight param I want and boom

def __init__(self,file,data=str):
self.file = file
self.data = data
try:
with open(self.file, 'x') as f:
pass
with open(self.file, "a") as CSVfile:
writer = csv.writer(CSVfile)
writer.writerow(['Time','Subject','Body','Notes'])
except:
pass
def __str__(self):
return "File is" + self.file
def readFile(self):
print("\nFile Contents:\n-----Start of File-----")
with open(self.file, "r+") as CSVfile:
reader = csv.reader(CSVfile)
for row in reader:
print(', '.join(row))
print("-----End of File----\n")
def printCurFile(self):
print("File accessed at " + self.file)
return self.file
def writeFile(self, time, subj, body, notes):
global timeStepper
if self.data == None:
print("No data provided.")
elif self.data == str:
with open(self.file, "a") as CSVfile:
writer = csv.writer(CSVfile)
writer.writerow([time,subj,body,notes])
29 changes: 29 additions & 0 deletions cscmuVatsimapi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from asyncore import write
from datetime import date
import calendar
from mimetypes import init
Expand All @@ -7,6 +8,8 @@
import json
import time
import os
import csv
from ccvaClasses import *

app.ticksPerSecond = 60

Expand All @@ -23,6 +26,10 @@

baseLink = "https://api.vatsim.net/api/"

curDT = str(time.time_ns())

curfile = "./data/datafile"+curDT+".csv"

initGroup = Group()
routeGroup = Group()

Expand Down Expand Up @@ -67,6 +74,11 @@ def jprint(obj):
vatsimID = CID.read().split('\n')[1]
CID.close()

def writeSomethingCSV(file,subj,body,notes):
csvCur = CurCSV(file)
curt = str(time.time_ns())
csvCur.writeFile(curt,subj,body,notes)

'''
This is the juicy stuff*. Val must be a JSON and what it does is it grabs the info from
the "result" entry in the main dict. The result from that is a list containing the
Expand Down Expand Up @@ -108,6 +120,10 @@ def initLogDir():
except FileNotFoundError:
os.mkdir("./logs/")
stdLogUpt("DIR UPD","'logs' dir not found. Creating new logs dir.")
try:
os.mkdir("./data/")
except:
pass

def stdLogUpt(subj,val):
route = ('./logs/log' + curDate + '.txt')
Expand Down Expand Up @@ -151,24 +167,29 @@ def testSample(lS):
connectAttempt = response.status_code
initGroupLineMaker = 25
if (connectAttempt == 200):
writeSomethingCSV(curfile,'Subject','Body Info','Notes(post scriptum)')
print("Return", connectAttempt)
print("Connection success.")
sucCon = Label("Connected to Vatsim API.",5,initGroupLineMaker,align="left",font="calibri",size=15,bold=True)
initGroupLineMaker += 25
initGroup.add(sucCon)
uptLog('INIT APP','App opened and is running properly.')
FTFF = testSample(initGroupLineMaker)
writeSomethingCSV(curfile,'INIT APP','App opened and is running properly.','Below is data recorded from SimConnect.')

else:
print("Error",connectAttempt)
erCon = Label(("Error",connectAttempt),5,initGroupLineMaker,align="left",font="calibri",size=15,bold=True)
initGroup.add(erCon)
initGroupLineMaker += 25
print("An unknown error has occured.")
uptLog("XX -|- FATAL ERROR -|- XX","An unknown error has occured. Network error No.",connectAttempt)
writeSomethingCSV(curfile,'FATAL ERROR','An unknown network error has occured.',f'Error code: {connectAttempt}')
erCon2 = Label("An unknown error has occured.",5,initGroupLineMaker,align="left",font="calibri",size=15,bold=True)
initGroup.add(erCon2)
initGroupLineMaker += 25
stopApp = Label("Stopping the App.",5,initGroupLineMaker,align="left",font="calibri",size=15,bold=True)
writeSomethingCSV(curfile,'APP STOP COMMAND','App is stopping.','This is the end of the file.')
app.stop()

eUI = "yes" # app.getTextInput("Enter GUI?").lower()
Expand All @@ -183,6 +204,7 @@ def testSample(lS):
if (clA == "yes"):
print("App stopped intentionally. Closing the program.")
uptLog("APP STOP", "App stopped intentionally.")
writeSomethingCSV(curfile,'APP STOP COMMAND','App is stopping.','This is the end of the file.')
app.stop()
else:
pass
Expand All @@ -193,6 +215,12 @@ def refreshRoute():
routeGroup.clear()
initRoute(FTFF)

def updateData():
writeSomethingCSV(curfile,'----','DATA PACKET START','----')
writeSomethingCSV(curfile,'NO DATA','No data is available to display.','This feature is not available, however if you see this it works :)')
writeSomethingCSV(curfile,'----','DATA PACKET END','----')
pass

def onStep():
if (guiUp == False):
pass
Expand All @@ -212,6 +240,7 @@ def onStep():
print(routeString)
refreshRoute()
stdLogUpt("Route Fetch",routeString)
updateData()
app.currentRefreshTick += 1


Expand Down

0 comments on commit dfa48ea

Please sign in to comment.