import ftplib from ftplib import FTP import pandas as pd import os, pyodbc from init import initial start_time = time.time() server, database, username, password, ftpserver, ftpusername, ftppassword, ftpDirectory, query, localDirectory, filename, format = initial( ) print('\nStarting connection to database %s' % database) #Connection String conn = pyodbc.connect('DRIVER={SQL Server Native Client 11.0};SERVER=' + server + ';DATABASE=' + database + ';UID=' + username + ';PWD=' + password) cursor = conn.cursor() print('\nSuccess connected to database') print('Starting connection to FTP %s' % ftpserver) # Try connecting to the server try: ftp = ftplib.FTP(ftpserver) ftp.login(user=ftpusername, passwd=ftppassword) print('Success connected to FTP %s' % ftpserver) except ftplib.all_errors as e: errorcode_string = str(e).split(None, 1)[0] print('Changing directory to' + ' ' + ftpDirectory)
def main(argv): """ PPDyn main() function """ parser = argparse.ArgumentParser(description='Plasma Particle Dynamics (PPDyn)') parser.add_argument('-i','--input', default='input.ini', type=str, help='Input file name') args = parser.parse_args() inputFile = args.input params = ini.parse(open(inputFile).read()) #========== Input Parameters =========== Lx = float(params['simbox']['Lx']) # System length in X Ly = float(params['simbox']['Ly']) # System length in Y Lz = float(params['simbox']['Lz']) # System length in Z N = int(params['particles']['N']) # Number of particles Vxmax = float(params['particles']['Vxmax']) # Maximum velocity in X Vymax = float(params['particles']['Vymax']) # Maximum velocity in Y Vzmax = float(params['particles']['Vzmax']) # Maximum velocity in Z k = float(params['screening']['k']) Temp = float(params['particles']['Temp']) tmax = float(params['time']['tmax']) # Final time dt = float(params['time']['dt']) # time step size Nt = round(tmax/dt) #number of time steps #========= Boundary ========== btype = str(params['boundary']['btype']) # Type of boundary #========= Diagnostics ======= dumpPeriod = int(params['diagnostics']['dumpPeriod']) path = "data/" # DO NOT CHANGE THE PATH os.makedirs(path, exist_ok=True) dumpData = bool(params['diagnostics']['dumpData']) f = h5py.File(path+"particle.hdf5","w") if dumpData: diagn.attributes(f,tmax,Lx,Ly,Lz,N,dt,dumpPeriod) dset = f.create_dataset('energy', (1,), maxshape=(None,), dtype='float64', chunks=(1,)) vtkData = bool(params['diagnostics']['vtkData']) realTime = bool(params['diagnostics']['realTime']) #========== Options ============ parallelMode = bool(params['options']['parallelMode']) if parallelMode: if btype == 'periodic': from pusher_parallel import verlet_periodic as verlet from init import initial_periodic as initial print("Running in Parallel Mode (Periodic boundary)") elif btype == 'reflecting': from pusher_parallel import verlet_reflecting as verlet from init import initial_reflecting as initial print("Running in Parallel Mode (Reflecting boundary)") else: if btype == 'periodic': from pusher_serial import verlet_periodic as verlet from init import initial_periodic as initial print("Running in Serial Mode (Periodic boundary)") elif btype == 'reflecting': from pusher_serial import verlet_reflecting as verlet from init import initial_reflecting as initial print("Running in Serial Mode (Reflecting boundary)") #========= Initialize ======== x,y,z,vx,vy,vz,ux,uy,uz,ax,ay,az,time,data_num = initial(Lx,Ly,Lz,Vxmax,Vymax,Vzmax,N,tmax,Nt,k,dumpPeriod) #========= Time Loop ========= for t in range(len(time)): KE = 0.0 # Reset KE x,y,z,vx,vy,vz,ux,uy,uz,ax,ay,az,KE = verlet(x,y,z,vx,vy,vz,ux,uy,uz,ax,ay,az,dt,Lx,Ly,Lz,N,KE,k) #============ Thermostat ========================= vx,vy,vz = berendsen(vx,vy,vz,dt,Temp,KE,N,t,tmax) #============ Diagnostics Write =================== if dumpData: if t%dumpPeriod==0: diagn.configSpace(f,dset,t,x,y,z,KE) print('TimeSteps = %d'%int(t)+' of %d'%Nt+' Energy: %e'%KE) if vtkData: from vtk_data import vtkwrite print('Writing VTK files for Paraview visualization ...') vtkwrite() return 0
import tweepy import re from translate import translate_text from init import initial API = initial() tweets = [] pages = [1, 2, 3, 4] fn = ["。", "?", "、、、", ":", "?", "!", "!", "...", "笑"] for p in pages: results = API.user_timeline(screen_name="D_kazuyan", exclude_replies=True, include_rts=False, count=200, page=p) for r in results: if not r.retweeted: text=re.sub(r'https?://[\w/:%#\$&\?\(\)~\.=\+\-…]+', "", r.text) text=re.sub('RT', "", text) text=re.sub('┃━━━━━━━━━━━━━┃', "", text) text=re.sub('お気に入り', "", text) text=re.sub('会食恐怖症', "", text) text=re.sub('質問箱', "", text) text=re.sub(r'(#[^\s]+)', "", text)#ハッシュタグ text=re.sub(r"@([A-Za-z0-9_]+)", "", text)#メンション text=re.sub(r'[︰-@]', "", text)#全角記号 text=re.sub('\n', "", text)#改行文字 if text and text[-1] not in fn: text += "。" tweets.append(text) # tweets.append(translate_text(text)) line = "".join(tweets) line += translate_text(line) # print(line)
from init import initial from chat import chatMsgHandler def pingCheck(line): # pdb.set_trace() if line == "PING :tmi.twitch.tv\r": print "Twitch sent ping request. Ready to pong" sendCommand("PONG :tmi.twitch.tv") return True return False if __name__ == "__main__": initial() buffer = "" while True: buffer = updateBuffer(buffer) strip_queue = string.split(buffer, "\n") buffer = strip_queue.pop() for line in strip_queue: print "\nNew line in strip_queue: ", line # Check to make sure twitch hasn't checked the bot is AFK pChk = pingCheck(line) if pChk: continue # Line has been evaluated, move to next