backup directory:, dir2# update file list source_files=comparame (DIR1,NBSP;DIR2) foriteminsource_files:# Replace the source directory path with the backup directory path Dest_item=re.sub (Dir1, dir2,item) # If you need to synchronize a directory, create a Ifos.path.isdir (item): Os.makedirs (Dest_item) # If you need to synchronize a file , copy Ifos.path.isfile (item): Shutil.copyfile (Item,dest_item) Main ()Finally, put this script into the crontab task.This article is from a "sense of dire
For the first time, try to write a complete and useful program in Python, which implements the ability to rename the specified file in the current file in a certain order, or a certain value.Paste the following code#coding: Utf-8Import OSperfix= ' Test ' #perfix为重命名后的文件起始字符Length=2#length the length of the file name to be reached after removing Perfixbase=1# The starting number of the file nameformat= ' txt ' #文件的后缀#函数PadLeft将文件名补全到指定长度#str为将要补全的字符#nu
#!/usr/bin/env python# _*_coding:utf-8_*_import osimport sysimport statvfsdef Main (): ' Deamon ' if ' Linux ' not in Sys.platform:print ' sorry! System Opreation not supply! ' Sys.exit (3) mount = [] result = [] label = [] status = 0 with open ('/proc/mounts ') as F:for V in F: v = v.split () Mountname = v[1] If v[0] in Mount:continue mou Nt.append (V[0]) TRY:VFS=OS.STATVFS (mountname) except Oserror:print ' Mounted Device error, p
Find the Python script for the more than 1 years directory:Note:1. Datetime.timedelta represents 2 time differenceVI a1.py#!/usr/bin/pythonImport OSImport datetimeDir= "/Home"now = Datetime.datetime.now ()Delta = Datetime.timedelta (days=365)Os.chdir (dir)For Root,dirs,files in Os.walk (dir):For F in dirs:if f = = "AA":Mtime = Datetime.datetime.fromtimestamp (Os.path.getmtime (Os.path.join (root,f)))If Mtime Print Os.path.join (root,f): WqPython a1.py
1. WindowsControl Panel--"management tool--" Task Scheduler-- Create Task Next is to set the timing of execution and script path, etc.1 "GeneralSet the task name description, and whether you need to log in when executing.2 "" TriggerThe trigger specifies when to execute, whether it is performed only once or repeatedly.3 "OperationThe task to be performed by the action settings is to execute our Python script on a timed basis, where the red box is cir
Show multiple statements on the same linePython can use multiple statements in the same row, with semicolons (;) split between statements, and here's a simple example:Instance (Python 3.0+)#!/usr/bin/python3 import sys; x = 'runoob'; sys. StdOut. Write(x + '\ n') Use the script to execute the above code, and the output is:RunoobExecuted using the interactive command line, the output is:>>>import sys; =' Runoob '; sys. StdOut. Write(+' \
The following code is tested under Python 2.6.6 Add an account and change your password: (Note: Linux expect command can also be completed, interactive auto-input function) #!/usr/bin/envpythonaccount= ' sl_t1 ' passwd= ' a1p2p3l4e5 ' cmd_useradd= ' useradd %s ' % (account) #添加用户命令, modify Importsubprocessas as needed spdefuseradd ():cmd= ' exportlc_all=en_us%s ' % (cmd _useradd) F=open ('/dev/null ', ' W ') ret=sp.call (cmd,shell=true,stdout=f, NBS
Gquan_article_info where crawl_time> '" +str (Two_hours_ago) + "'")Results = Cursor.fetchall ();Count = 0For row in results:Count = Row[0]Print "Info\t Current time:" + str (currtime) + "\ t two hours before the crawl quantity is:" +str (count)if Count = = 0:Tag = Mailutil.send_mail (Mailto_list, ' You have no data in your lap news data stream for two hours ', ' you have problems with your lap news stream, please check (47 database Gquan_article_info) to fix!!!!!! ')If tag:Print "Error\t Curren
The function of this script is to uninstall all third-party apps installed in Android phone, mainly using adb shell pm, adb Uninstall command, so the premise is to use the environment variable of ADB, the following code:1 #!/usr/bin/env python2 3 ImportOS4 5 defUninstall ():6Os.popen ("adb wait-for-device")7 Print "Start Uninstall ..."8 forPackagesinchOs.popen ("adb shell pm list packages-3"). ReadLines ():9PackageName = Packages.split (":") [-1].splitlines () [0]TenOs.popen ("adb Unins
Obtain and verify HTTP Proxy Python scripts in batches.
HTTP brute force cracking, credential stuffing, and some common skills, such:
1. When scanning Renren's network, I encountered a single account error twice and required to enter the verification code. The other party did not implement the IP policy.
I used to maintain the 0.1 million (username, password) queue to bypass the verification code. When a us
Shell:Log_date= ' date-d "1 day Ago" +%y-%m-%d ' #以指定格式设置一天前的年份月份日期aws S3 ls $LAST 5_base_path > ${tmp_file} #将s3这个位置的文件清单输出到tmp . txt files if grep-q $LOG _date $TMP _file; Then #查找是否存在spark-submit--master "local[*]"/root/downloads/packagestat/selecttopnapppackage.py $TEST _1 $TEST _2 $ Android_output_base_path $IOS _output_base_path #提交py文件加输入参数Python:Eval function: Convert the string "{Key:value}" to a dictionaryDatetime.strptime (date_string, format): Converts a format string to a DateTime o
This article mainly introduces how to access the mdb database through Python scripts in Linux. This example is based on the debian Linux system. If you need a friend, refer to connect to the mdb database in linux, if you connect directly, the default mdb driver cannot identify non-windows paths, so you cannot use conventional connections.
Method
DRIVER={Microsoft Access Driver (*.mdb)};DBQ=c:\\dir\\file.m
+ '/' + self.dir.encode (' GBK ')) Self.imgList.sort ( SELF.CMP) def setchapterpage (self,page,chapter): Self.nowpage = Pageif Self.flag = = 0: # Execute code that should be executed in the constructor Self.flag = 1self . Setdictready () if Self.nowchapter! = Chapter: # If you do not need to change the current folder, do not reset the working directory Self.nowchapter = Chapterself.setdictready () Self.target = self.generateaddr (page,chapter) self.sendAddr.emit (QstrinG (Self.target), Self.now
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.