def dt_conv(datetime): dw, day, month, year, tim, delt = datetime.split(' ') months_name2num = dict((v, k) for k, v in enumerate(calendar.month_abbr)) #tim = tim.split(':') #tim[0] = int(tim[0])+int(delt[1:3]) #tim[1] = int(tim[1])+int(delt[3:]) #hour = tim[0] month = months_name2num[month] year, month, day = jalali.Gregorian(int(year), month, int(day)).persian_tuple() month = date_convert(month) ptime = str(day) + ' ' + month + ' ' + str(year) return ptime
def take_date_per(self): import ConvertToPersian import jalali # print('picture_factory : Picture : take_date_per : file = ', self.__path) # print('picture_factory : Picture : take_date_per : jalali_take_date = ', self.__take_date) file_date = self.take_date() jalali_take_date = jalali.Gregorian( file_date).persian_string_full_format() # print('picture_factory : Picture : take_date_per : jalali_take_date = ', jalali_take_date) pic_take_date_per = ConvertToPersian.getPer(jalali_take_date) return pic_take_date_per
def main(project_name): # try: # current_work = sys.argv[1] # except IndexError: # print("please specify your project") # exit(1) dt = datetime.datetime.now() try: time.sleep(100000000000000) except KeyboardInterrupt: dt2 = datetime.datetime.now() current_georgian_date = "{0}-{1}-{2}".format(dt2.year, dt2.month, dt2.day) current_persian_date = jalali.Gregorian(dt.year, dt.month, dt.day).persian_string() duration = (dt2 - dt).total_seconds() date = (current_georgian_date, str(dt), str(dt2), duration, project_name, current_persian_date) datasource = dataSource.DataSource('working_dates.db') datasource.insert_data(date)
def calc(self): year = self.edt_year.text() month = self.edt_month.text() day = self.edt_day.text() if year and month and day: if self.radioButton_jtg.isChecked(): months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ] DayL = [ 'Mon', 'Tues', 'Wednes', 'Thurs', 'Fri', 'Satur', 'Sun' ] newd = jalali.Persian( (int(year), int(month), int(day))).gregorian_tuple() self.label_year.setText("Year: " + str(newd[0])) self.label_month.setText("Month: " + str(newd[1]) + " / " + months[int(str(newd[1])) - 1]) self.label_day.setText("Day: " + str(newd[2])) self.label_dow.setText("DoW: " + str(DayL[ datetime.date(newd[0], newd[1], newd[2]).weekday()])) elif self.radioButton_gtj.isChecked(): months = [ 'Farvardin', 'Ordibehesht', 'Khordad', 'Tir', 'Mordad', 'Shahrivar', 'Mehr', 'Aban', 'Azar', 'Dey', 'Bahman', 'Esfand' ] DayL = [ 'Do Shanbe', 'Se Shanbe', 'Chahar Shanbe', 'Panj Shanbe', 'Jome', 'Shanbe', 'Yek Shanbe' ] newd = jalali.Gregorian( (int(year), int(month), int(day))).persian_tuple() self.label_year.setText("Year: " + str(newd[0])) self.label_month.setText("Month: " + str(newd[1]) + " / " + months[int(str(newd[1])) - 1]) self.label_day.setText("Day: " + str(newd[2])) self.label_dow.setText("DoW: " + str(DayL[ datetime.date(int(year), int(month), int(day)).weekday()]))
def createOutData(): with open("Beta/inData/stocks_urls.csv", "r", newline="", encoding="utf-8") as file: reader = csv.reader(file) df_index = pd.read_csv("Beta/inData/index/index.csv" ) # Making dataFrame from index's csv file. df_index.set_index('date', inplace=True) drop_list = list( ) # This is dropping list for drop in the end of indexing proccess. for row in reader: # Loop through csv stock files. file_url = "Beta/inData/stocks/" + row[ 0] + ".csv" # Creating stock's csv file url. df_stock = pd.read_csv( file_url) # Making dataFrame from stock's csv file. row_count, _ = df_stock.shape for row_stock in df_stock.itertuples( ): # Looping through stock's dataFrame. gregorian = str(row_stock.date) g_year = gregorian[0:4] g_month = gregorian[4:6] g_day = gregorian[6:] j_year, j_month, j_day = jalali.Gregorian( g_year + ',' + g_month + ',' + g_day).persian_tuple() if j_month < 10: j_month = "0" + str(j_month) if j_day < 10: j_day = "0" + str(j_day) j_date = int( str(j_year) + str(j_month) + str(j_day)) # Jalali date is for searching from df_index. try: index_return = df_index.loc[ j_date, 'return'] # Trying to get index_return from df_index based on jalali date. df_stock.iloc[ row_stock.Index, 3] = index_return # Writing index_return value to df_stock where needed. if row_stock.Index + 1 == row_count: raise Exception( "For loop finished before index_reuturn ended.") except: # Getting exception when df_index.loc[j_date, 'return'] throws IndexError. # TODO: Some stock data's are till 139500101 so the if never executes. # TODO: Then drop list contains the indexes for last stocks miss for drop. if (j_date < 13950101) or (row_stock.Index + 1 == row_count): df_stock = df_stock.iloc[:row_stock. Index] # Index now is less than date so we don't need that in dataframe. for item in drop_list: df_stock.drop(item, axis=0, inplace=True) drop_list.clear() break df_stock.iloc[row_stock.Index, 3] = "------------" drop_list.append(row_stock.Index) ''' df_stock.drop(row_stock.Index, inplace=True) The problem with drop: Suppose, the row that we want to delete is called 'D' has the index of 10 and the next row is called 'N' and has the index of 11. If we call the drop method for 'D', it drops the row and sets the index of 'N' to 10. Now, the problem is that the next loop is going to start from 11 because it was in 10. So, the row 'N' is not going to be proccessed. ''' df_stock.to_csv( "Beta/outData/stocks/" + row[0] + ".csv", index=False, encoding="utf-8-sig" ) # Writes new dataFrame to outData stock csv file.
global number_reader global first_code_number global image_view, mthreading image_view = False mthreading = False #print(sys.argv) image_view, mthreading, walk_days = main(sys.argv[1:]) if not os.path.exists(data_path): os.mkdir(data_path) drivermain = webdriver.Firefox(options=options) drivermain.get('http://www.rrk.ir/News/NewsList.aspx') number_reader = findnumber() first_code_number = 0 while (walk_days < max_walk_days): today = date.today() - timedelta(days=walk_days) today_shamsi = jalali.Gregorian(today).persian_string( "{}{:02d}{:02d}") print(today_shamsi) #alert=drivermain.switch_to.alert #alert.accept() #time.sleep(5) NewsDate_input = drivermain.find_element_by_id( 'cphMain_dteFromNewspaperDate_dteFromNewspaperDate_txtDate' ) NewsDate_input.send_keys(today_shamsi) #time.sleep(5) try: btn_search = drivermain.find_element_by_id( 'cphMain_btnSearch') btn_search.click()
def main(): analytics = initialize_analyticsreporting() limit_date = datetime.datetime.now().date() ref_date = validation(analytics) for i in range((limit_date - ref_date).days - 1): step_time = ref_date + relativedelta(days=+i) # step_time_str = step_time.strftime('%Y-%m-%d') # first_str = step_time.replace(day=1).strftime('%Y-%m-%d') year, month = jalali.Gregorian(step_time).persian_tuple()[0:2] persian_start = jalali.Persian(year, month, 1).gregorian_datetime() df_part1 = fetch_data(analytics, step_time.strftime('%Y-%m-%d')) df_part1.columns = ['date', 'sessions', 'dailyUsers'] df_part2 = fetch_data_monthly( analytics, step_time.replace(day=1).strftime('%Y-%m-%d'), step_time.strftime('%Y-%m-%d')) df_part2.columns = ['month', 'monthlyUsers'] if persian_start.year == step_time.year: df_part3 = fetch_data_jalali(analytics, persian_start.strftime('%Y-%m-%d'), step_time.strftime('%Y-%m-%d'), 1) df_part3.columns = ['monthlyUsersJalali', 'year'] df_part3.drop(['year'], axis=1, inplace=True) else: df_part3 = fetch_data_jalali(analytics, persian_start.strftime('%Y-%m-%d'), step_time.strftime('%Y-%m-%d'), 2) df_part3.columns = ['irrelevant', 'monthlyUsersJalali'] df_part3.drop(['irrelevant'], axis=1, inplace=True) df_part1['date'] = pd.to_datetime(df_part1['date']) total_df = pd.concat([df_part1, df_part2, df_part3], axis=1) total_df.drop(['month'], axis=1, inplace=True) try: cursor.fast_executemany = True sql_comm = '''INSERT INTO [{}].[dbo].[{}] ([date],[sessions],[dailyUsers],[monthlyUsers],[monthlyUsersJalali]) VALUES (?,?,?,?,?)'''.format( DB_NAME, TABLE_NAME) cursor.executemany(sql_comm, total_df.values.tolist()) cursor.commit() doc = create_log('Insert', 'Ack', step_time, socket.gethostname(), 'Successful Insert', server_len=len(total_df.index), database_len=len(total_df.index)) es.index(index="textlogs-{}".format(INDX), doc_type='log', body=doc) except Exception as e: doc = create_log('Insert', 'Nack', step_time, socket.gethostname(), str(e)) es.index(index="textlogs-{}".format(INDX), doc_type='log', body=doc) sys.exit() time.sleep(2)
def Output(data): "This funtion predicts and sends out the output xml to the client browser" print("Content-type: text/xml") print print("<?xml version='1.0' encoding='UTF-8' ?>") print("<results>") if not data[0]: print("\t<error>") print("\t\t<message>%s</message>" % data[1]) print("\t</error>") print("</results>") if data[0]: tndt = int(data[1]) tcdt = int(data[2]) hour = int(data[3]) minute = int(data[4]) dates = [] now0 = datetime.datetime.now() now1 = now0 + datetime.timedelta(days=1) now2 = now0 + datetime.timedelta(days=2) now3 = now0 + datetime.timedelta(days=3) now4 = now0 + datetime.timedelta(days=4) now5 = now0 + datetime.timedelta(days=5) now6 = now0 + datetime.timedelta(days=6) year0 = now0.year month0 = now0.month day0 = now0.day year1 = now1.year month1 = now1.month day1 = now1.day year2 = now2.year month2 = now2.month day2 = now2.day year3 = now3.year month3 = now3.month day3 = now3.day year4 = now4.year month4 = now4.month day4 = now4.day year5 = now5.year month5 = now5.month day5 = now5.day year6 = now6.year month6 = now6.month day6 = now6.day date0_year = jalali.Gregorian( str(year0) + "-" + str(month0) + "-" + str(day0)).persian_year date1_year = jalali.Gregorian( str(year1) + "-" + str(month1) + "-" + str(day1)).persian_year date2_year = jalali.Gregorian( str(year2) + "-" + str(month2) + "-" + str(day2)).persian_year date3_year = jalali.Gregorian( str(year3) + "-" + str(month3) + "-" + str(day3)).persian_year date4_year = jalali.Gregorian( str(year4) + "-" + str(month4) + "-" + str(day4)).persian_year date5_year = jalali.Gregorian( str(year5) + "-" + str(month5) + "-" + str(day5)).persian_year date6_year = jalali.Gregorian( str(year6) + "-" + str(month6) + "-" + str(day6)).persian_year date0_month = jalali.Gregorian( str(year0) + "-" + str(month0) + "-" + str(day0)).persian_month date1_month = jalali.Gregorian( str(year1) + "-" + str(month1) + "-" + str(day1)).persian_month date2_month = jalali.Gregorian( str(year2) + "-" + str(month2) + "-" + str(day2)).persian_month date3_month = jalali.Gregorian( str(year3) + "-" + str(month3) + "-" + str(day3)).persian_month date4_month = jalali.Gregorian( str(year4) + "-" + str(month4) + "-" + str(day4)).persian_month date5_month = jalali.Gregorian( str(year5) + "-" + str(month5) + "-" + str(day5)).persian_month date6_month = jalali.Gregorian( str(year6) + "-" + str(month6) + "-" + str(day6)).persian_month date0_day = jalali.Gregorian( str(year0) + "-" + str(month0) + "-" + str(day0)).persian_day date1_day = jalali.Gregorian( str(year1) + "-" + str(month1) + "-" + str(day1)).persian_day date2_day = jalali.Gregorian( str(year2) + "-" + str(month2) + "-" + str(day2)).persian_day date3_day = jalali.Gregorian( str(year3) + "-" + str(month3) + "-" + str(day3)).persian_day date4_day = jalali.Gregorian( str(year4) + "-" + str(month4) + "-" + str(day4)).persian_day date5_day = jalali.Gregorian( str(year5) + "-" + str(month5) + "-" + str(day5)).persian_day date6_day = jalali.Gregorian( str(year6) + "-" + str(month6) + "-" + str(day6)).persian_day if date0_day >= 1 and date0_day <= 9: date00_day = "0" + str(date0_day) else: date00_day = str(date0_day) if date1_day >= 1 and date1_day <= 9: date11_day = "0" + str(date1_day) else: date11_day = str(date1_day) if date2_day >= 1 and date2_day <= 9: date22_day = "0" + str(date2_day) else: date22_day = str(date2_day) if date3_day >= 1 and date3_day <= 9: date33_day = "0" + str(date3_day) else: date33_day = str(date3_day) if date4_day >= 1 and date4_day <= 9: date44_day = "0" + str(date4_day) else: date44_day = str(date4_day) if date5_day >= 1 and date5_day <= 9: date55_day = "0" + str(date5_day) else: date55_day = str(date5_day) if date6_day >= 1 and date6_day <= 9: date66_day = "0" + str(date6_day) else: date66_day = str(date6_day) if date0_month >= 1 and date0_month <= 9: date00_month = "0" + str(date0_month) else: date00_month = str(date0_month) if date1_month >= 1 and date1_month <= 9: date11_month = "0" + str(date1_month) else: date11_month = str(date1_month) if date2_month >= 1 and date2_month <= 9: date22_month = "0" + str(date2_month) else: date22_month = str(date2_month) if date3_month >= 1 and date3_month <= 9: date33_month = "0" + str(date3_month) else: date33_month = str(date3_month) if date4_month >= 1 and date4_month <= 9: date44_month = "0" + str(date4_month) else: date44_month = str(date4_month) if date5_month >= 1 and date5_month <= 9: date55_month = "0" + str(date5_month) else: date55_month = str(date5_month) if date6_month >= 1 and date6_month <= 9: date66_month = "0" + str(date6_month) else: date66_month = str(date6_month) date0 = str(date0_year) + "-" + date00_month + "-" + date00_day date1 = str(date1_year) + "-" + date11_month + "-" + date11_day date2 = str(date2_year) + "-" + date22_month + "-" + date22_day date3 = str(date3_year) + "-" + date33_month + "-" + date33_day date4 = str(date4_year) + "-" + date44_month + "-" + date44_day date5 = str(date5_year) + "-" + date55_month + "-" + date55_day date6 = str(date6_year) + "-" + date66_month + "-" + date66_day dates.append(date0) dates.append(date1) dates.append(date2) dates.append(date3) dates.append(date4) dates.append(date5) dates.append(date6) test = [] db = MySQLdb.connect("localhost", "root", "S_njf1372", "bsc_thesis") cursor = db.cursor() query = ("SELECT * FROM dates WHERE dt = '%s' ") % (date0) cursor.execute(query) results = cursor.fetchall() for row in results: Day = str(row[1]) Month = str(row[2]) Season = str(row[3]) Day_Of_Week = str(row[4]) Is_Holiday = str(row[5]) Date_Importance = str(row[6]) test.append([ tndt, long(tcdt * 10000000), int(Day), int(Month), int(Season), int(Day_Of_Week), int(Is_Holiday), float(Date_Importance), float(hour + minute / 60.00) ]) query = ("SELECT * FROM dates WHERE dt = '%s' ") % (date1) cursor.execute(query) results = cursor.fetchall() for row in results: Day = str(row[1]) Month = str(row[2]) Season = str(row[3]) Day_Of_Week = str(row[4]) Is_Holiday = str(row[5]) Date_Importance = str(row[6]) test.append([ tndt, long(tcdt * 10000000), int(Day), int(Month), int(Season), int(Day_Of_Week), int(Is_Holiday), float(Date_Importance), float(hour + minute / 60.00) ]) query = ("SELECT * FROM dates WHERE dt = '%s' ") % (date2) cursor.execute(query) results = cursor.fetchall() for row in results: Day = str(row[1]) Month = str(row[2]) Season = str(row[3]) Day_Of_Week = str(row[4]) Is_Holiday = str(row[5]) Date_Importance = str(row[6]) test.append([ tndt, long(tcdt * 10000000), int(Day), int(Month), int(Season), int(Day_Of_Week), int(Is_Holiday), float(Date_Importance), float(hour + minute / 60.00) ]) query = ("SELECT * FROM dates WHERE dt = '%s' ") % (date3) cursor.execute(query) results = cursor.fetchall() for row in results: Day = str(row[1]) Month = str(row[2]) Season = str(row[3]) Day_Of_Week = str(row[4]) Is_Holiday = str(row[5]) Date_Importance = str(row[6]) test.append([ tndt, long(tcdt * 10000000), int(Day), int(Month), int(Season), int(Day_Of_Week), int(Is_Holiday), float(Date_Importance), float(hour + minute / 60.00) ]) query = ("SELECT * FROM dates WHERE dt = '%s' ") % (date4) cursor.execute(query) results = cursor.fetchall() for row in results: Day = str(row[1]) Month = str(row[2]) Season = str(row[3]) Day_Of_Week = str(row[4]) Is_Holiday = str(row[5]) Date_Importance = str(row[6]) test.append([ tndt, long(tcdt * 10000000), int(Day), int(Month), int(Season), int(Day_Of_Week), int(Is_Holiday), float(Date_Importance), float(hour + minute / 60.00) ]) query = ("SELECT * FROM dates WHERE dt = '%s' ") % (date5) cursor.execute(query) results = cursor.fetchall() for row in results: Day = str(row[1]) Month = str(row[2]) Season = str(row[3]) Day_Of_Week = str(row[4]) Is_Holiday = str(row[5]) Date_Importance = str(row[6]) test.append([ tndt, long(tcdt * 10000000), int(Day), int(Month), int(Season), int(Day_Of_Week), int(Is_Holiday), float(Date_Importance), float(hour + minute / 60.00) ]) query = ("SELECT * FROM dates WHERE dt = '%s' ") % (date6) cursor.execute(query) results = cursor.fetchall() for row in results: Day = str(row[1]) Month = str(row[2]) Season = str(row[3]) Day_Of_Week = str(row[4]) Is_Holiday = str(row[5]) Date_Importance = str(row[6]) test.append([ tndt, long(tcdt * 10000000), int(Day), int(Month), int(Season), int(Day_Of_Week), int(Is_Holiday), float(Date_Importance), float(hour + minute / 60.00) ]) db.close() target = open("../file/test.txt", 'w') for index in test: target.write(str(index[0])) target.write(",") target.write(str(index[1])) target.write(",") target.write(str(index[2])) target.write(",") target.write(str(index[3])) target.write(",") target.write(str(index[4])) target.write(",") target.write(str(index[5])) target.write(",") target.write(str(index[6])) target.write(",") target.write(str(index[7])) target.write(",") target.write(str(index[8])) target.write("\r\n") target.close() command = 'python test.py' subprocess.call(command, shell=True) target = open("../file/test.txt", 'r') lines = target.read().split("\r\n") i = 0 for index in lines: if len(index) != 0: print("\t<result>") print("\t\t<date>%s</date>" % dates[i]) print("\t\t<class>%s</class>" % index[0]) print("\t</result>") i = i + 1 target.close() print("</results>")
def createFile(cntV): logcreateFile = Logger(filename="__init__", level=__level__, dirname="File-" + os.path.basename( __file__) + "-Func-" + sys._getframe().f_code.co_name, rootdir=__LOGDIR__) cntV += 1 # region check_is_file_pna_exist fileExist = str(Vn_FILENAME[0]) if os.path.isfile(__ARC__ + fileExist): try: os.remove(__ARC__ + fileExist) createFile(1) except OSError as e: logcreateFile.error("ERROR: %s - %s." % (str(e.filename), str(e.strerror))) # endregion check_is_file_pna_exist # region create_file if not os.path.isfile(__ARC__ + fileExist): try: cntFile = 0 # region open_and_fill_file for Vn_PKEY, Vn_RES1, Vn_TR_PROCCESSING_CODE, Vn_TR_DATE, Vn_TR_TIME, \ Vn_TR_TRANS_NO, Vn_CARD_NUMBER_PRINT, Vn_TR_IMD, Vn_TR_TERM_NO, Vn_TR_AMOUNT, \ Vn_TERM_TYPE_CODE, Vn_RES2, Vn_RES3, Vn_RES4, Vn_CLMCB_ACC_NO, Vn_RES5, Vn_RES6, \ Vn_PSP_SPEC, Vn_FIN_DOC_NUM, Vn_TR_DATE_2, Vn_FUNC_CODE, Vn_CARD_NUMBER, Vn_RES7, \ Vn_TR_RETRIVAL_NO in listforIterable: cntFile += 1 with open(__ARC__ + str(Vn_FILENAME[0]), 'a', encoding='windows-1256') as configfile: # saveFile # create file for bank with format shaparak.ir try: global Vm_FILEMILADIDATE Vm_FILEMILADIDATE = V_FTPS_RMT_DIR + "/" + Vi_FILEMILADIDATE configfile.write( Vn_PKEY + "|" + Vn_RES1 + "|" + Vn_TR_PROCCESSING_CODE + "|" + jalali.Gregorian(Vn_TR_DATE).persian_string("{0}/{1}/{2}") + "|" + jalali.Gregorian(Vn_TR_TIME).persian_string("{0}/{1}/{2}") + "|" + datetime.strptime(Vn_TR_TIME, '%H:%M:%S') + "|" + Vn_TR_TRANS_NO + "|" + Vn_CARD_NUMBER_PRINT + "|" + Vn_TR_IMD + "|" + Vn_TR_TERM_NO + "|" + Vn_TR_AMOUNT + "|" + Vn_TERM_TYPE_CODE + "|" + Vn_RES2 + "|" + Vn_RES3 + "|" + Vn_RES4 + "|" + Vn_CLMCB_ACC_NO + "|" + Vn_RES5 + "|" + Vn_RES6 + "|" + Vn_PSP_SPEC + "|" + Vn_FIN_DOC_NUM + "|" + Vn_TR_DATE_2 + "|" + Vn_FUNC_CODE + "|" + Vn_CARD_NUMBER + "|" + Vn_RES7 + "|" + Vn_TR_RETRIVAL_NO + "\n") configfile.close() except EnvironmentError as ex: # parent of IOError, OSError *and* WindowsError where available logcreateFile.warning( "ERROR IN CREATE FILE " + __confiFileName__ + " -> REGION CREATE_FILE") logcreateFile.error("ERROR MASSAGE: " + str(ex)) configfile.close() # noinspection PySimplifyBooleanCheck if __debugMODE__.upper() == 'TRUE': Important_single_log("__DEBUG_MODE__", "Parameter debug is: " + str(__debugMODE__)) Important_single_log("__DEBUG_MODE__", "---- count of record write to file is: " + str(cntFile) + "#FILE" + " ----") Important_single_log("__DEBUG_MODE__", "---- count of record write to file is: " + str(V_REC_VIEW) + "#VIEW" + str(cntV) + " ----") except NameError as error: logcreateFile.error("ERROR MASSAGE: " + str(error)) except EnvironmentError as ex: # parent of IOError, OSError *and* WindowsError where available logcreateFile.warning("ERROR IN CREATE" + __confiFileName__ + " -> createFile()") logcreateFile.error("ERROR MASSAGE: " + str(ex)) except TypeError as e: logcreateFile.error("UNEXPECTED ERROR REGION CREATE_FILE TypeError: " + str(e)) except: logcreateFile.error("UNEXPECTED ERROR REGION CREATE_FILE #1:" + str(sys.exc_info()[0]))