-
Notifications
You must be signed in to change notification settings - Fork 0
/
T4Wk3.py
112 lines (83 loc) · 2.19 KB
/
T4Wk3.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
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
103
104
105
106
107
108
109
110
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Oct 16 15:15:11 2024
@author: marcus
"""
from time import time, ctime, gmtime
import os
import sys
import csv
## speedtest
##
# Get time
def get_time():
t = time()
return (ctime(t)) #, gmtime(t))
pcTime = get_time()
# Get OS name
os_name = os.name
# Get OS type
osType = sys.platform
# check to see if file exists...?
#fileName = "testfolder"
fileName = "testfile.csv"
# isExists = os.path.exists(fileName)
# print(isExists)
isFile = os.path.isfile(fileName)
# print(isFile)
# isFile = os.path.isdir(fileName)
# print(isFile)
header = ['Time', 'ostype', 'osname']
def writeHeader():
with open(fileName, mode='w') as file:
writer = csv.writer(file)
writer.writerow(header)
print("Headers written.\nNow extracting data from PC")
if isFile == True:
print("File exists") #... extracting data from PC")
fileKeep = input("Want to Delete or Continue (C/D)?")
if fileKeep.upper() == "D" or fileKeep.upper() == "DELETE":
print("Deleting file")
os.remove(fileName)
writeHeader()
else:
print("Continuing")
else:
print("File not found... writing headers.")
writeHeader()
# data = [str(pcTime + "'," + osType + "," + os_name)] # incorrect data type of string
data = [pcTime, osType, os_name]
print(data)
print(type(data))
## pause
print("let's pause")
userInput = input()
# open for writing
# with open("testfile.csv", 'a') as f:
# f.write(str(pcTime + "," + osType + "," + os_name))
# print("read as text file\n")
# with open('testfile.csv', 'r') as f:
# print(f.read())
print("read as CSV file\n")
# exampleFile = open('testfile.csv')
# exampleReader = csv.reader(exampleFile)
# exampleData = list(exampleReader)
# print(exampleData)
### NICER OPENING
def readCSVFile():
with open(fileName, mode='r') as file:
csvFile = csv.reader(file)
for lines in csvFile:
print(lines)
def seperator():
print("---------------------")
seperator()
print("reading file before adding data")
seperator()
readCSVFile()
seperator()
with open(fileName, mode='a') as file:
writer = csv.writer(file)
writer.writerow(data)
readCSVFile()