-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_to_text_file.py
169 lines (123 loc) · 5.59 KB
/
input_to_text_file.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import os
TicketStatus = "Completed"
TicketDescription = "Upgraded Laptop"
def StartUp():
# Checks to see if the Tickets Directory exists or not.
print("Checking Tickets Directory:")
if os.path.isdir('./Tickets') == True:
print("./Tickets directory was found.\n")
else:
print("ERROR! ./Tickets directory could not be found.\n")
GetTickets()
def GetTickets():
# Checks the existing ticket to find out what the next ticket number should be.
print("Checking Current tickets:")
# This will get the 6 numerical digits of each file in the Tickets directory, this should pull all existing ticket numbers.
x = [f[1:7] for f in os.listdir('./Tickets')]
# This will print out all the tickets.
print("{}\n".format(x))
print("Last ticket found:\n{}\n".format(max(x)))
# This will calculate and formulate the next ticket number to be used.
NextTicket = int(max(x)) + 1
print("The next ticket will be:\n{}\n".format("%06d" % (NextTicket)))
return NextTicket
def master():
# Needs to read tickets directory and find the last number that was used and start the counter 1 after that.
# If the last ticket was 000046, then the counter should start at 47.
# Main Menu
print("""
#####################################################################
### Ticket_Master.py ###
#####################################################################
# #
# Hello, and welcome to Ticket_Master.py! #
# #
# #
# #
# #
# #
# #
# #
#####################################################################
# #
# Select from the following files: #
# 1 - Open a new Ticket #
# 2 - Open an exsiting Ticket #
# 3 - List all tickets #
# 4 - #
# #
#####################################################################
""")
Selection = input("What would you like to do?\n")
while Selection != 3:
print("Please select one of the options above")
Selection = input("What would you like to do?\n")
if Selection == 1:
return
elif Selection == 2:
return
elif Selection == 3:
print("")
GetTickets()
#master()
elif Selection == 4:
return
#Ticket Numbering System:
# T000001
#File name structure:
# T000001 - Status - Description.txt
#Ticket Contents:
# Ticket Number:
# Requester:
# Request:
# Creation Date:
# Date Modified:
# Notes:
# Resolution:
# Status:
# Durration:
def CreateTicket():
GetNextTicket = GetTickets()
print("YOOO The next ticket will be:\n{}\n".format("%06d" % (GetNextTicket)))
print("")
def PrintTicket():
# Imports the next ticket number from "def GetTickets()"
GetNextTicket = GetTickets()
# "%06d" % (TicketNumber,) Will print the TicketNumber variable and ensure that the number is 6 digits, with 0's in front.
# This is useful, because it lets you keep the TicketNumeber as an INT for processing.
# This will create a new txt file with the next ticket number found above, and print a few lines into the text file.
with open("Tickets/T{} - {} - {}.txt".format("%06d" % (GetNextTicket), TicketStatus, TicketDescription), "w") as TXT:
print("Ticket Number: {}".format("%06d" % (GetNextTicket)), file=TXT)
print("", file=TXT)
print("Status: {}".format(TicketStatus), file=TXT)
print("", file=TXT)
print("Desctiption: {}".format(TicketDescription), file=TXT)
print("T{} - {} - {}.txt was created successfully".format("%06d" % (GetNextTicket), TicketStatus, TicketDescription))
def ReadTicket():
# Imports the next ticket number from "def StartUp()"
# GetNextTicket = StartUp()
GetNextTicket = 4
print("Checking Current tickets:")
# This will get the 6 numerical digits of each file in the Tickets directory, this should pull all existing ticket numbers.
x = [f[1:7] for f in os.listdir('./Tickets')]
# This will print out all the tickets.
print("{}\n".format(x))
if "000057" in x:
print('success')
print(max(x))
print("%06d" % (GetNextTicket))
if x == GetNextTicket:
print("yes")
else:
print("no")
print("Last ticket found:\n{}\n".format(max(x)))
#NEEDS TO BE CHANGED TO FIND A TICKET BASED ON ONLY THE TICKET NUMBER, NOT THE WHOLE STRING.
# ‘r’ – Read mode which is used when the file is only being read
file = open("Tickets/T{} - {} - {}.txt".format("%06d" % (GetNextTicket), TicketStatus, TicketDescription), "r")
print(file.read())
#print(file)
#master()
StartUp()
CreateTicket()
PrintTicket()
ReadTicket()