def test06(self): # Reassign stdout for the duration of the test. saved_stdout = sys.stdout try: sys.stdout = StringIO() d = date.Date(3, 2, 1990) d.subNDays(5) self.assertEqual( sys.stdout.getvalue().strip(), '03/02/1990\n03/01/1990\n02/28/1990\n02/27/1990\n02/26/1990\n02/25/1990' ) self.assertEqual(str(d), '02/25/1990') sys.stdout.close() sys.stdout = StringIO() d = date.Date(1, 5, 2015) d.subNDays(7) self.assertEqual( sys.stdout.getvalue().strip(), '01/05/2015\n01/04/2015\n01/03/2015\n01/02/2015\n01/01/2015\n12/31/2014\n12/30/2014\n12/29/2014' ) self.assertEqual(str(d), '12/29/2014') sys.stdout.close() finally: sys.stdout.close() sys.stdout = saved_stdout
def test05(self): # Reassign stdout for the duration of the test. saved_stdout = sys.stdout try: sys.stdout = StringIO() d = date.Date(2, 26, 1980) d.addNDays(5) self.assertEqual( sys.stdout.getvalue().strip(), '02/26/1980\n02/27/1980\n02/28/1980\n02/29/1980\n03/01/1980\n03/02/1980' ) self.assertEqual(str(d), '03/02/1980') sys.stdout.close() sys.stdout = StringIO() d = date.Date(12, 29, 2012) d.addNDays(7) self.assertEqual( sys.stdout.getvalue().strip(), '12/29/2012\n12/30/2012\n12/31/2012\n01/01/2013\n01/02/2013\n01/03/2013\n01/04/2013\n01/05/2013' ) self.assertEqual(str(d), '01/05/2013') sys.stdout.close() finally: sys.stdout.close() sys.stdout = saved_stdout
def test10(self): self.assertEqual(date.Date(12, 7, 1941).dow(), 'Sunday') self.assertEqual(date.Date(10, 28, 1929).dow(), 'Monday') self.assertEqual(date.Date(10, 19, 1987).dow(), 'Monday') self.assertEqual(date.Date(1, 1, 2100).dow(), 'Friday') self.assertEqual(date.Date(2, 26, 1979).dow(), 'Monday') self.assertEqual(date.Date(10, 12, 2013).dow(), 'Saturday') self.assertEqual(date.Date(2, 11, 2015).dow(), 'Wednesday') self.assertEqual(date.Date(5, 19, 2015).dow(), 'Tuesday') self.assertEqual(date.Date(5, 14, 2015).dow(), 'Thursday')
def test_init_raise(self): "Does date.Date.__init__ raise exceptions correctly?" badArgs = (None, "", 1.0, (), [], {}) now = datetime.datetime.now() #Bad data type for year, month, day arguments. for badArg in badArgs: with self.assertRaises(TypeError): d = date.Date(now.month, now.day, badArg) for badArg in badArgs: with self.assertRaises(TypeError): d = date.Date(badArg, now.month, now.year) for badArg in badArgs: with self.assertRaises(TypeError): d = date.Date(now.month, badArg, now.year) #Bad value for month argument. with self.assertRaises(ValueError): d = date.Date(0, now.day, now.year) with self.assertRaises(ValueError): d = date.Date(datetime.date.max.month + 1, now.day, now.year) #Bad value for day argument. for month in range(1, datetime.date.max.month + 1): with self.assertRaises(ValueError): d = date.Date(month, 0, now.year) with self.assertRaises(ValueError): d = date.Date(month, 0, now.year) daysInThisMonth = TestDateMethods.daysInMonth(month, now.year) with self.assertRaises(ValueError): d = date.Date(month, daysInThisMonth + 1, now.year)
def test01(self): d = date.Date(1, 13, 2000) d.tomorrow() self.assertEqual(str(d), '01/14/2000') d = date.Date(2, 27, 2015) d.tomorrow() self.assertEqual(str(d), '02/28/2015') d.tomorrow() self.assertEqual(str(d), '03/01/2015') d = date.Date(2, 28, 2016) d.tomorrow() self.assertEqual(str(d), '02/29/2016') d = date.Date(12, 31, 2012) d.tomorrow() self.assertEqual(str(d), '01/01/2013')
def test02(self): d = date.Date(1, 13, 2000) d.yesterday() self.assertEqual(str(d), '01/12/2000') d = date.Date(3, 1, 2015) d.yesterday() self.assertEqual(str(d), '02/28/2015') d.yesterday() self.assertEqual(str(d), '02/27/2015') d = date.Date(3, 1, 2016) d.yesterday() self.assertEqual(str(d), '02/29/2016') d = date.Date(1, 1, 2014) d.yesterday() self.assertEqual(str(d), '12/31/2013')
def test04(self): d = date.Date(1, 1, 2014) c = d.copy() self.assertTrue(d.equals(c)) d.yesterday() c.yesterday() self.assertTrue(c.equals(d))
def test_ajoutDeJoursQuiChangentDAnnee(self): date0 = date.Date() date1 = date0.plus(jours=9) assert date1.annee == date0.annee + 1 assert date1.mois == 0 assert date1.jour == 1
def test_ajoutDeJoursSansChangerDeMois(self): date0 = date.Date() # 23 décembre 2020 date1 = date0.plus(jours=5) assert date1.annee == date0.annee assert date1.mois == date0.mois assert date1.jour == 28
def get_or_create_date(clock_str): full_date_of_input = clock_str[11:21] for d in dates: if d.get_full_date() == full_date_of_input: return d new_date = date.Date(clock_str) dates.append(new_date) return new_date
def test03(self): self.assertTrue(date.Date(1, 13, 2000).equals(date.Date(1, 13, 2000))) d = date.Date(2, 27, 2015) d.tomorrow() self.assertTrue(d.equals(date.Date(2, 28, 2015))) d.yesterday() self.assertTrue(d.equals(date.Date(2, 27, 2015))) self.assertFalse(d.equals(date.Date(2, 27, 2016))) self.assertFalse(d.equals(date.Date(2, 28, 2015))) self.assertFalse(d.equals(date.Date(3, 27, 2015)))
def test09(self): d1 = date.Date(11, 9, 2011) d2 = date.Date(12, 16, 2011) self.assertEqual(d2.diff(d1), 37) self.assertEqual(d1.diff(d2), -37) d1 = date.Date(11, 9, 2011) d2 = date.Date(5, 18, 2012) self.assertEqual(d2.diff(d1), 191) self.assertEqual(d1.diff(d2), -191) d1 = date.Date(11, 9, 2011) self.assertEqual(d1.diff(date.Date(4, 24, 1899)), 41106) self.assertEqual(d1.diff(date.Date(1, 1, 1899)), 41219) self.assertEqual(d1.diff(date.Date(9, 16, 2124)), -41219) self.assertEqual(d1.diff(date.Date(1, 1, 2101)), -32560)
def test_ajoutDeJoursSansChangerDAnnees(self): date0 = date.Date() date0.mois = 8 # 23 septembre 2020 date1 = date0.plus(jours=42) assert date1.annee == date0.annee assert date1.mois == 10 assert date1.jour == 4
def test_ajoutDHeuresQuiChangentDeJour(self): date0 = date.Date() # 23 décembre 2020 19:30:00 date1 = date0.plus(heures=5) assert date1.annee == date0.annee assert date1.mois == date0.mois assert date1.jour == 24 assert date1.heure == 0 assert date1.minute == date0.minute
def test_ajoutDHeuresSansChangerDeJour(self): date0 = date.Date() # 23 décembre 2020 19:30:00 date1 = date0.plus(heures=2) assert date1.annee == date0.annee assert date1.mois == date0.mois assert date1.jour == date0.jour assert date1.heure == 21 assert date1.minute == date0.minute
def test_ajoutMinutes(self): date0 = date.Date() # 23 décembre 2020 19:30:00 date1 = date0.plus(minutes=270) # 4h30 assert date1.annee == 2020 assert date1.mois == 11 assert date1.jour == 24 assert date1.heure == 0 assert date1.minute == 0
def test_ajoutDureeCombinee(self): date0 = date.Date() # 23 décembre 2020 19:30:00 date1 = date0.plus(jours=21, heures=2, minutes=20, secondes=15) assert date1.annee == 2021 assert date1.mois == 0 assert date1.jour == 13 assert date1.heure == 21 assert date1.minute == 50 assert date1.seconde == 15
def generate_dates(): """The generate_dates function returns a list of day objects. In later builds this function may take user input to generate specific weeks or months. """ available_dates = [] # For loop generates days 21-25 for i in range(21, 26): # All generated dates will be in January 2019 available_dates.append(date.Date(1, i, 2019)) return available_dates
def test_ajoutSecondes(self): date0 = date.Date() # 23 décembre 2020 19:30:00 date1 = date0.plus(secondes=15) assert date1.annee == date0.annee assert date1.mois == date0.mois assert date1.jour == date0.jour assert date1.heure == date0.heure assert date1.minute == date0.minute assert date1.seconde == 15
def getStationTime(grdMODEL, year, ID): """ Find the day and month that the SODA file respresents based on the year and ID number. Each SODA file represents a 5 day average, therefore we let the date we find be the first day of those 5 days. Thats the reason we subtract 4 below for day of month. """ """ Create a date object to keep track of Julian dates etc. Also create a reference date starting at 1948/01/01. """ ref_date = date.Date() ref_date.day = 1 ref_date.month = 1 ref_date.year = 1948 jdref = ref_date.ToJDNumber() days = 0.0 month = 1 loop = True while loop is True: d = date.NumberDaysMonth(month, year) if days + d < int(ID) * 5: days = days + d month += 1 else: day = int(int(ID) * 5 - days) loop = False soda_date = date.Date() soda_date.day = day soda_date.month = month soda_date.year = year jdsoda = soda_date.ToJDNumber() yyyymmdd = '%s/%s/%s' % (soda_date.year, soda_date.month, soda_date.day) message = 'Current time of SODA file : %s/%s/%s' % ( soda_date.year, soda_date.month, soda_date.day) return jdsoda - jdref, yyyymmdd, message
def test_ajoutDHeuresQuiChangentDeMois(self): date0 = date.Date() date0.mois = 8 date0.jour = 28 # 28 septembre 2020 19:30:00 date1 = date0.plus(heures=72) assert date1.annee == date0.annee assert date1.mois == 9 assert date1.jour == 1 assert date1.heure == date0.heure assert date1.minute == date0.minute
def test_nextDay(self): "Does date.nextDay increment the Date object?" now = datetime.datetime.now() jan1 = datetime.date(now.year, 1, 1) daysInYear = TestDateMethods.daysInYear(now.year) for i in range(daysInYear): c = jan1 + datetime.timedelta(days = i) d = date.Date(c.month, c.day, c.year) d.nextDay() tomorrow = c + datetime.timedelta(days = 1) self.assertEqual(str(d), tomorrow.strftime("%m/%d/%Y"))
def getCourseStatsOnDay(self, i, day, month, year, mp): # Store complete (original) list of assignments originalAssign = [] for x in range(len(self.courses[i].assignments)): originalAssign.append(self.courses[i].assignments[x]) # Consider only assignments in that marking period d1 = extractor.mpStartDates[mp][0] m1 = extractor.mpStartDates[mp][1] y1 = extractor.mpStartDates[mp][2] mpStartDate = date.Date(d1, m1, y1) # Create array of only assignments posted before inputted date tempAssign = [] for x in range(len(self.courses[i].assignments)): d = self.courses[i].assignments[x].datetimePosted d = date.Date(d.day, d.month, d.year) # If assignment date posted is before date specified in parameters if ((d.date.year < year) | ((d.date.year == year) & ((d.date.month < month) | ((d.date.month == month) & (d.date.day <= day))))): # if (mpStartDate.compareToDateObj(d)<=0): tempAssign.append(self.courses[i].assignments[x]) # Get course grade as of the entered date self.courses[i].assignments = tempAssign self.courses[i].calculateCurrentMPGrade() grade = round(self.courses[i].currentMPGrade * 100, 2) numPtsRec = self.courses[i].getTotalPointsRec() numPtsWorth = self.courses[i].getTotalPointsWorth() retArr = [grade, numPtsRec, numPtsWorth] # Restore course assignments list to original self.courses[i].assignments = originalAssign return retArr
def test_init(self): "Does date.__init__ construct the correct object?" now = datetime.datetime.now() #so we can get the current year jan1 = datetime.date(now.year, 1, 1) daysInYear = TestDateMethods.daysInYear(now.year) for i in range(daysInYear): c = jan1 + datetime.timedelta(days = i) d = date.Date(c.month, c.day, c.year) self.assertEqual(d.getYear(), c.year) self.assertEqual(d.getMonth(), c.month) self.assertEqual(d.getDay(), c.day) self.assertEqual(d.dayOfYear(), c.timetuple().tm_yday) self.assertEqual(str(d), c.strftime("%m/%d/%Y"))
def test_nextDays_raise(self): "Does date.Date.nextDays raise exceptions correctly?" badArgs = (None, "", 1.0, (), [], {}) now = datetime.datetime.now() d = date.Date(now.month, now.day, now.year) #Bad data type for argument. for badArg in badArgs: with self.assertRaises(TypeError): d.nextDays(badArg) #Bad value for argument. with self.assertRaises(ValueError): d.nextDays(-1)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Apr 27 14:46:22 2020 @author: devinpowers """ ################################################################################ ## Demonstration program for class Date ################################################################################ import date A = date.Date(1, 1, 2014) print(A) print(A.to_iso()) print(A.to_mdy()) print(A.is_valid()) print() B = date.Date(12, 31, 2014) print(B) print(B.to_iso()) print(B.to_mdy()) print(B.is_valid()) print() C = date.Date()
################################################################################ ## Demonstration program for class Date ################################################################################ import date A = date.Date(12, 30, 2017) print(A) print(A.to_iso()) print(A.to_mdy()) print(A.is_valid()) print() B = date.Date(12, 31, 2014) print(B) print(B.to_iso()) print(B.to_mdy()) print(B.is_valid()) print() C = date.Date() C.from_iso("2014 07 04") print(C) print(C.to_iso()) print(C.to_mdy()) print(C.is_valid()) print()
def chooseDate(self): return_front_end_dict = '' cf = common_functions.Common_functions() dt = date.Date() date1 = {"date_id": "1"} date2 = {"date_id": "2"} date3 = {"date_id": "3"} data1 = cf.getFromCsv('date.csv', date1) data2 = cf.getFromCsv('date.csv', date2) data3 = cf.getFromCsv('date.csv', date3) if len(data1) == 0: return_front_end_dict = '{ "data": [], "status":"error", "message":"No Date in ' 'date.csv' '" }' elif len(data2) == 0: return_front_end_dict = '{ "data": [], "status":"error", "message":"No Date in ' 'date.csv' '" }' elif len(data3) == 0: return_front_end_dict = '{ "data": [], "status":"error", "message":"No Date in ' 'date.csv' '" }' else: start_date1 = self.returnSecondSunday(int(data1[0]['year']), int(data1[0]['month'])) start_date2 = self.returnSecondSunday(int(data2[0]['year']), int(data2[0]['month'])) start_date3 = self.returnSecondSunday(int(data3[0]['year']), int(data3[0]['month'])) new_data = [{}] new_data[0]['camp_time_slots1'] = str( start_date1) + " 00:00:00.000000" new_data[0]['camp_time_slots2'] = str( start_date2) + " 00:00:00.000000" new_data[0]['camp_time_slots3'] = str( start_date3) + " 00:00:00.000000" end_date1 = start_date1 + datetime.timedelta(days=13) end_date2 = start_date2 + datetime.timedelta(days=13) end_date3 = start_date3 + datetime.timedelta(days=13) display_date1 = str(start_date1.day) + self.suffix( start_date1.day) + '-' + str(end_date1.day) + self.suffix( end_date1.day) + " " + start_date1.strftime( "%B") + " " + str(end_date1.year) display_date2 = str(start_date2.day) + self.suffix( start_date2.day) + '-' + str(end_date2.day) + self.suffix( end_date2.day) + " " + start_date2.strftime( "%B") + " " + str(end_date2.year) display_date3 = str(start_date3.day) + self.suffix( start_date3.day) + '-' + str(end_date3.day) + self.suffix( end_date3.day) + " " + start_date3.strftime( "%B") + " " + str(end_date3.year) new_data[0]['display_date1'] = display_date1 new_data[0]['display_date2'] = display_date2 new_data[0]['display_date3'] = display_date3 return_front_end_dict = '{ "data": ' + json.dumps( new_data) + ', "status":"success", "message":"" }' return return_front_end_dict
]: absname = "%s%s_port%d%s_%s" % \ (report_dir, str(yesterday), port, ip_proto, orderby) nf.readLog(start_datetime, end_datetime, 1, options=["-s", "srcip/"+orderby, "-n", "0", \ "dst port %s and (%s)" % \ (str(port), iplists.getNetList("src",ip))], file_name=absname) # For uplink absname = report_dir + str( yesterday) + "_uplink" + ip_proto + "_" + orderby nf.readLog(start_datetime, end_datetime, 1, options=["-s", "srcip/"+orderby, "-n", "0", "%s" % \ iplists.getNetList("src",ip)], file_name=absname) # For downlink absname = "%s%s_downlink%s_%s" % \ (report_dir, str(yesterday), ip_proto, orderby) nf.readLog(start_datetime, end_datetime, 1, options=["-s", "dstip/"+orderby, "-n", "0", "%s" % \ iplists.getNetList("dst",ip)], file_name=absname) if __name__ == '__main__': d = date.Date() yesterday, start_datetime, end_datetime = d.datetimeYesterday() report(yesterday, start_datetime, end_datetime)
def manageData(): # Get current MP based on current date currentDate = datetime.datetime.today() currentDateObj = date.Date(currentDate.day, currentDate.month, currentDate.year) # currentMPindex = 3 # for i in range(0,4): # mpStartDate = date.Date(mpStartDates[i][0],mpStartDates[i][1],mpStartDates[i][2]) # if(currentDateObj.compareToDateObj(mpStartDate)<0): # currentMPindex = i-1 # if(currentMPindex<0): # Current date is outside of school year # currentMPindex = 3 # 4th marking period numDaysInSchoolYear = 0 for mp in range(0, currentMPindex + 1): # print("MP: " + str(mp+1)) startDate = date.datetime.date(mpStartDates[mp][2], mpStartDates[mp][1], mpStartDates[mp][0]) endDate = date.datetime.date(mpStartDates[mp + 1][2], mpStartDates[mp + 1][1], mpStartDates[mp + 1][0] - 1) daysInMP[mp] = endDate.__sub__(startDate).days numDaysInSchoolYear += daysInMP[mp] #endDate.__sub__(startDate).days firstDay = datetime.date(mpStartDates[0][2], mpStartDates[0][1], mpStartDates[0][0]) print("FIRST DAY: ") print(firstDay) # for mp in range(len(coursesAllMPs)): # for c in range(len(coursesAllMPs[mp])): # print(coursesAllMPs[mp][c].courseName) # print("\n") # exit(0) print("NUM DAYS IN SCHOOL YEAR: " + str(numDaysInSchoolYear)) data = [[[list]]] * (numDaysInSchoolYear + 1) for m in range(0, currentMPindex + 1): print("M: " + str(m)) courseDataAllMPs = [[]] dm = dataManager.DataManager(studentName, studentID, coursesAllMPs[m], m) for c in range(len(coursesAllMPs[m])): dailyGrades = dm.getDailyCourseGradesForMP(c, m) for d in range(len(dailyGrades)): daysSinceStartOfYear = dailyGrades[d][0].__sub__( firstDay).days - 1 # print(str(firstDay) + "\t" + str(dailyGrades[d][0]) + "\t" + str(daysSinceStartOfYear)) # for asdf in range(len(dailyGrades[d])): # print(dailyGrades[d][asdf]) # print(daysSinceStartOfYear) try: data[daysSinceStartOfYear - 1].append(dailyGrades[d]) except IndexError: print("IndexError") # exit(0) allData = [ [[[]]] ] # [course][[[date,grade,ptsRec,ptsW],...] for mp1, [[date,grade,ptsRec,ptsW],...] for mp2, ...] # allData[0][0][0][1] = [AP ENG/LANG & COMP][mp1][2019-09-01][grade] for c in range(0, len(coursesAllMPs[0])): courseDataAllMPs = [[[]]] for x in range(0, currentMPindex + 1): mp = x dm = dataManager.DataManager(studentName, studentID, coursesAllMPs[mp], mp) dailyGrades = dm.getDailyCourseGradesForMP(c, mp) courseDataAllMPs.append(dailyGrades) courseDataAllMPs.pop(0) allData.append(courseDataAllMPs) allData.pop(0) # allData2 = [list]*len(allData[0][0]) allData2 = [[[]]] # [[date[course[infotype]]]...for all dates] for m in range(0, len(allData[0])): for d in range(len(allData[0][m])): # for every day in MP if (d <= numDaysInSchoolYear): arrC = [] for c in range(len(coursesAllMPs[m])): # for every course arr = [ allData[c][m][d][1], allData[c][m][d][2], allData[c][m][d][3] ] arrC.append(arr) arrDC = [allData[0][m][d][0], arrC] # [date,[info1,info2,info3]] allData2.append(arrDC) allData2.pop(0) # OUTPUT DATA TO FILE try: outfile = open("dailyGradesFile.txt", "x") except FileExistsError: outfile = open("dailyGradesFile.txt", "w") try: # json_outfile = open("gradesDictionary.json",'rb+') # except: # print("RB+ DID NOT WORK ----------------------------------") # try: json_outfile = open("gradesDictionary.json", 'x') except: json_outfile = open("gradesDictionary.json", 'w') json_outfile.write("[") mpIndexPlus1 = 1 for d in range(len(allData2)): dDate = date.Date(allData2[d][0].day, allData2[d][0].month, allData2[d][0].year) endDate = date.Date(mpStartDates[4][0], mpStartDates[4][1], mpStartDates[4][2]) if (dDate.compareToDateObj(endDate) >= 0): break # Stop at last day of school # print(str(allData2[d][0])) outfile.write(str(allData2[d][0]) + "\n") # write date for c in range(len(allData2[d][1])): try: if (date.Date(allData2[d][0].day, allData2[d][0].month, allData2[d][0].year).compareToDMY( mpStartDates[mpIndexPlus1][0], mpStartDates[mpIndexPlus1][1], mpStartDates[mpIndexPlus1][2]) >= 0): mpIndexPlus1 += 1 lstLbls = ["Date", "Course", "Grd", "PR", "PW"] lst = [] if (len(coursesAllMPs[mpIndexPlus1 - 1][c].code) > 0): lst = [ str(allData2[d][0]), coursesAllMPs[mpIndexPlus1 - 1][c].courseName, allData2[d][1][c][0], allData2[d][1][c][1], allData2[d][1][c][2] ] # print("\t{0:30} {1:15} {2:15} {3:15}".format(coursesAllMPs[mpIndexPlus1-1][c].courseName+":: ","Grd:"+str(allData2[d][1][c][0]),"PR:"+str(allData2[d][1][c][1]),"PW:"+str(allData2[d][1][c][2]))) outfile.write("\t{0:30} {1:15} {2:15} {3:15}\n".format( coursesAllMPs[mpIndexPlus1 - 1][c].courseName + ":: ", "Grd:" + str(allData2[d][1][c][0]), "PR:" + str(allData2[d][1][c][1]), "PW:" + str(allData2[d][1][c][2]))) else: lst = [ str(allData2[d][0]), coursesAllMPs[mpIndexPlus1 - 1][c].courseName, "----", "----", "----" ] # print("\t{0:30} {1:15} {2:15} {3:15}".format(coursesAllMPs[mpIndexPlus1-1][c].courseName+":: ","Grd:----","PR:----","PW:----")) outfile.write("\t{0:30} {1:15} {2:15} {3:15}\n".format( coursesAllMPs[mpIndexPlus1 - 1][c].courseName + ":: ", "Grd:----", "PR:----", "PW:----")) with open("gradesDictionary.json", 'a') as json_outfile: json.dump(Convert(lstLbls, lst), json_outfile, indent=2) if (d != len(allData2) - 1 or c != len(allData2[d][1]) - 1): json_outfile.write(",\n") except IndexError: break # json_outfile.close() # # Delete last comma # with open("gradesDictionary.json",'rb+') as json_outfile: # # move to end, then scan forward until a non-continuation byte is found # json_outfile.seek(-1, os.SEEK_END) # while json_outfile.read(1) & 0xC0 == 0x80: # # we just read 1 byte, which moved the file position forward, # # skip back 2 bytes to move to the byte before the current. # json_outfile.seek(-2, os.SEEK_CUR) # # last read byte is our truncation point, move back to it. # json_outfile.seek(-1, os.SEEK_CUR) # json_outfile.truncate() # json_outfile.close() with open("gradesDictionary.json", 'a') as json_outfile: json_outfile.write("]") json_outfile.close()