示例#1
0
def DownloadReport(scsm,reportnumber):
	#Attempt to download report
	reporturl='report/'+str(reportnumber)+'/download'
	if DEBUG:
		print "Report is ready to download"
		print "Report URL:",reporturl
	represp=scsm.post(reporturl,json={'id': int(reportnumber)})
	if DEBUG:
		print "Report response",represp
		print "Report response text",represp.text

		
	#Since writing large CSV files in one go seems to spike CPU usage,
	# just write one character at a time to allow the CPU an opportunity
	# to switch.
	print time.ctime()," Writing report to output.csv"
	f=open('output.csv','wb')
	i=0
	l=len(represp.content)
	print "Total bytes to write:",l
	x=10000000
	while i < l:
		f.write(represp.content[i:(i+x)])
		i=i+x
		time.sleep(1)
	f.close

	return(True)
示例#2
0
 def file_stat_from_directory(self, directory):
     modified = time.ctime(os.path.getmtime(directory))
     created = time.ctime(os.path.getctime(directory))
     extension = os.path.splitext(directory)[1]
     file_name = ntpath.basename(directory).replace(extension, '')
     return {
         'file_name': file_name,
         'created': created,
         'modified': modified,
         'directory': directory,
         'extension': extension
     }
    def get_labeled(self, file_name):
        hash = self.get_hash(file_name)
        i = Image.open(file_name)
        info = i._getexif()
        labeled = {}
        labeled.update({"File Path": file_name})
        kb = format(os.path.getsize(file_name) / 1024, '.2f')
        mb = format(os.path.getsize(file_name) / 1048576, '.2f')
        labeled.update({"Size(KB)": kb})
        labeled.update({"Size(MB)": mb})
        labeled.update({"HASH-5": hash})

        labeled.update({"                Exif ": "MetaData Details"})
        try:
            if (info != None):
                for (key, val) in info.items():
                    labeled[TAGS.get(key)] = val
            else:

                print('File         :', file_name)
                print('Modified time:',
                      time.ctime(os.path.getmtime(file_name)))
                print('Size        :',
                      format(os.path.getsize(file_name) / 1024,
                             '.2f'), "KB  /",
                      format(os.path.getsize(file_name) / 1048576, '.2f'),
                      "MB")

                labeled.update(
                    {"Created": time.ctime(os.path.getctime(file_name))})
                labeled.update(
                    {"Modified": time.ctime(os.path.getmtime(file_name))})

            dirname, basename = os.path.split(file_name)
            f = open(basename + '.txt', 'w+')
            f.write(
                " ################################################################## \n"
            )
            f.write(" IMAGE METADATA DETAILS \n \n")
            for i in labeled:
                print(i, ' : ', labeled[i])
                labeled[i] = str(labeled[i])
                f.write(i)
                f.write("   :     ")
                f.write(labeled[i])
                f.write("\n")
        except:
            print("Exception 1 Read ")

        return labeled
示例#4
0
def main():
    f = open("testtextfile.txt", "w+")
    f = open(
        "testtextfile.txt", "a"
    )  # to append data to an existing file content instead of overriding
    for i in range(10):
        f.write("This is line " + str(i) + "\r\n")
    f.close()
    # read whole file
    f = open("testtextfile.txt", "r")
    if f.mode == 'r':
        content = f.read()
        print(content)

    #Read line by line
    f = open("testtextfile.txt", "r")
    if f.mode == 'r':
        fl = f.readlines()
        for x in fl:
            print(x)

    #Path utils
    print(os.name)

    print("Item exists: " + str(path.exists("testtextfile.txt")))
    print("Item is a file: " + str(path.isfile("testtextfile.txt")))
    print("Item is a directory: " + str(path.isdir("testtextfile.txt")))
    print("Item path: " + str(path.realpath("testtextfile.txt")))
    print("Item path and Name: " +
          str(path.split(path.realpath("testtextfile.txt"))))

    t = time.ctime(path.getmtime("testtextfile.txt"))
    print(t)
    print(datetime.datetime.fromtimestamp(path.getmtime("testtextfile.txt")))
示例#5
0
def main():
    # Print the name of the OS
    print(os.name)

    # Check for item existence and type
    print("Item exists: {}".format(str(path.exists("textfile.txt"))))
    print("Item is a file: {}".format(path.isfile("textfile.txt")))
    print("Item is a directory: {}".format(path.isdir("textfile.txt")))

    # Work with file paths
    print("Item path: {}".format(path.realpath("textfile.txt")))
    print("Item path and name: {}".format(
        path.split(path.realpath("textfile.txt"))))

    # Get the modification time
    t = time.ctime(path.getmtime("textfile.txt"))
    print("Item modification time: {}".format(t))
    t2 = datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))
    print("Item modification time: {}".format(t2))

    # Calculate how long ago the item was modified
    td = datetime.datetime.now() - t2
    print("Item has been {} since the file was modified".format(td))
    print("Item has been {} seconds since the file was modified".format(
        td.total_seconds()))
def main():
    # Print the name of the OS
    #'nt' means that you are running windows, and 'posix' mac.
    print(os.name)

    # Check for item existence and type
    print("The item exits : " + str(path.exists('textfile.txt')))
    print("The item is a file : " + str(path.isfile('textfile.txt')))
    print("The item is a folder : " + str(path.isdir('textfile.txt')))

    # Work with file paths
    print("Item path : " + str(path.realpath('textfile.txt')))
    print("Item path and name : " +
          str(path.split(path.realpath('textfile.txt'))))

    # Get the modification time (getmtime)
    t = time.ctime(path.getmtime('textfile.txt'))
    print(t)

    # Calculate how long ago the item was modified
    current_time = datetime.datetime.now()
    td = current_time - datetime.datetime.fromtimestamp(
        path.getmtime("textfile.txt"))
    print("It has been " + str(td) + " since the file was modified")
    print("Or, " + str(td.total_seconds()) + " seconds")
示例#7
0
def main():
  # Print the name of the OS
  print(os.name)


  # Check for item existence and type
  # print("Item exists: " + str(path.exists("textfile.txt")))
  # print("Item is a file: " + str(path.isfile("textfile.txt")))
  # print("Item is a directory: " + str(path.isdir("textfile.txt")))

  # print("Path of the file: " + str(path.realpath("textfile.txt")))
  # print("File Name and Path: " + str(path.split(path.realpath("textfile.txt"))))
  # Work with file paths

  
  # Get the modification time
  t = time.ctime(path.getmtime("textfile.txt"))
  print(t)
  #same thing done by line 27, 28 can be done as
  print(datetime.datetime.fromtimestamp(path.getmtime("textfile.txt")))
  
  # Calculate how long ago the item was modified
  td = datetime.datetime.now() - datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))

  print("It has been " + str(td) + " since the file was modified")
  print("Or, "+ str(td.total_seconds()) + " seconds")
示例#8
0
def main():
    # print name of the OS
    print(os.name)

    # Check for item existence and type
    print("Item exists: " + str(path.exists("sachin.txt")))
    print("Item is file: " + str(path.isfile("sachin.txt")))
    print("Item is directory: " + str(path.isdir("sachin.txt")))

    # Work with file paths
    print("Item's path: " + str(path.realpath("sachin.txt")))
    print("Item's path and name: " +
          str(path.split(path.realpath("sachin.txt"))))

    # Get the modification time
    t = time.ctime(path.getmtime("sachin.txt"))
    print(t)
    print(datetime.datetime.fromtimestamp(path.getmtime("sachin.txt")))
    print("======================================================")
    # calcualate how long time ago the item was modified
    current_time = datetime.datetime.now()
    print(current_time)
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(
        path.getmtime("sachin.txt"))
    print("It has been " + str(td) + "since the file was modified")
    print("In Seconds: " + str(td.total_seconds()))
示例#9
0
def main():
    # Print the name of the OS
    print(os.name)

    # Check for item existence and type
    path_name = "learning_python/ch4/textfile.txt"
    print(f"Item exists: {path.exists(path_name)}")
    print(f"Item is a file: {path.isfile(path_name)}")
    print(f"Item is a directory: {path.isdir(path_name)}")

    # Work with file paths
    print(f"Item path: {path.realpath(path_name)}")
    print(f"Item path and name: {path.split(path.realpath(path_name))}")

    # Get the modification time
    # ctime converts the modification time to a real time
    # getmtime returns the modification time
    last_mod_time = time.ctime(path.getmtime(path_name))
    print(last_mod_time)
    last_mod_time = datetime.datetime.fromtimestamp(path.getmtime(path_name))
    print(last_mod_time)

    # Calculate how long ago the item was modified
    time_since_last_mod = datetime.datetime.now() - last_mod_time
    print(f"It has been {time_since_last_mod} since the file was modified")
    print(f"Or, {time_since_last_mod.total_seconds()} seconds")
def main():
    print("main")
    #Print the name of the OS
    print(os.name)

    #Pring the name of current directory
    print(os.getcwd())

    #Check for item existence and type
    print("Item exists: " + str(path.exists("textfile.txt")))
    print("Item is a file: " + str(path.isfile("textfile.txt")))
    print("Item is a directory: " + str(path.isdir("textfile.txt")))

    #Work with file paths
    print("Item path: " + str(path.realpath("textfile.txt")))
    print("Item path and name:" +
          str(path.split(path.realpath("textfile.txt"))))

    #Get the modification time
    t = time.ctime(path.getmtime("textfile.txt"))
    print(t)  # format Thu Dec 19 13:04:59 2019
    print(datetime.datetime.fromtimestamp(
        path.getmtime("textfile.txt")))  # format 2019-12-19 13:04:59.664423

    #Calculate how long ago the item was modified
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(
        path.getmtime("textfile.txt"))
    print("It has been " + str(td) + " since the file was modified")
    print("Or, " + str(td.total_seconds()) + " seconds")
def main():
  # Print the name of the OS
  print(os.name)
  
  # Check for item existence and type
  print("Item exists: " + str(path.exists("textfile.txt")))
  print("Item is a file: " + str(path.isfile("textfile.txt")))
  print("Item is a directory: " + str(path.isdir("textfile.txt")))
  
  print("----")
  # Work with file paths
  print("Item path: " + str(path.realpath("textfile.txt")))
  print("Item path and name: " + str(path.split(path.realpath("textfile.txt"))))
  
  print("----")
  # Get the modification time
  t = time.ctime(path.getmtime("textfile.txt"))
  print(t)
  print (datetime.datetime.fromtimestamp(path.getmtime("textfile.txt")))
  
  print("----")
  # Calculate how long ago the item was modified
  tNow = datetime.datetime.now()
  tModified = datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))
  print("It has been changed '" + str(tNow - tModified) + "' ago!")
示例#12
0
def main():
    # Refactor: declare variable to hold file name
    file_name = "text_file.txt"

    # Print the name of the OS
    print("Operative System: " + os.name)

    # Check for item existence and type
    print("Item exists: " + str(path.exists(file_name)))
    print("Item is a file: " + str(path.isfile(file_name)))
    print("Item is a directory: " + str(path.isdir(file_name)))

    # Work with file paths
    modification_timestamp = path.getmtime(file_name)

    print("Item path: " + str(path.realpath(file_name)))
    print("Item path and name: " + str(path.split(path.realpath(file_name))))

    # Get the modification time
    time_of_modification = time.ctime(modification_timestamp)
    print("Time of modification: " + time_of_modification)
    print(datetime.datetime.fromtimestamp(modification_timestamp))

    # Calculate how long ago the item was modified
    total_time = datetime.datetime.now() - datetime.datetime.fromtimestamp(
        modification_timestamp)
    print("It has been " + str(total_time) + " since the file was modified")
    print("Or, " + str(total_time.total_seconds()) + " seconds")
示例#13
0
def main():

    # Open a file for writing and create it if does not exist
    with open("textfile.txt", 'w+') as f:
        for i in range(10):
            f.write("This is line no: %d\r\n" %(i+1))

    with open("textfile.txt", 'r') as f:
        contents = f.read()
        #print(contents)

    # print the name of the os
    print("OS name: ", os.name)

    # check for the existence and type
    print("Item exists: ", path.exists("textfile.txt"))
    print("Item is a file: ", path.isfile("textfile.txt"))
    print("Item is a directory: ", path.isdir("textfile.txt"))

    # work with file paths
    print("File full path: ", path.realpath("textfile.txt"))
    print("File's path and name: ", path.split(path.realpath("textfile.txt")))

    # get the modification time of the file
    t = time.ctime(path.getmtime("textfile.txt"))
    print(t)
    print(datetime.datetime.fromtimestamp(path.getmtime("textfile.txt")))

    # calculate the time diff between last modification
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))
    print("It has been " + str(td) + " since the file has been modified")
    print("Or, " + str(td.total_seconds()) + " seconds")
示例#14
0
def main():
    # code goes here
    print("--OS Path--")
    print("OS Name: ", os.name)

    # check existance of file
    print("Item exists: " + str(path.exists("textfile.txt")))
    print("Item is a file: " + str(path.isfile("textfile.txt")))
    print("Item is a dir: " + str(path.isdir("textfile.txt")))

    # work with full path
    print("Item real path: " + str(path.realpath("textfile.txt")))
    print("Item path and name: " + str(path.split(path.realpath("textfile.txt"))))

    ## get modification time
    t = time.ctime(path.getmtime("textfile.txt"))
    print("Modified time: " + t)
    print(datetime.datetime.fromtimestamp(path.getmtime("textfile.txt")))

    # calculate how long ago the item was modified
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(
        path.getmtime("textfile.txt")
    )
    print("It has been " + str(td) + " since last file modified.")
    print("or " + str(td.total_seconds()) + " seconds")
示例#15
0
def emailconfirm():
    password_recovery_database = TechDataBase(
        mysql, "password_recovery")  # INIT Базы с восстановления
    message = None
    if request.method == "POST":
        email_form = request.form.get("email")
        email = re.search(r"[\w.-]+@[\w.-]+\.?[\w]+?", email_form)
        if email:
            userrow = users_database.getRow("email",
                                            email.group())  # Поиск почты в бд
            if userrow != "null":
                access_hash = generate_password_hash(time.ctime())
                expires = (datetime.now() +
                           timedelta(hours=1)).strftime('%Y-%m-%d %H:%M:%S')
                password_recovery_database.delRow("user_id", userrow[0])
                password_recovery_database.addSomeRow(
                    ("user_id", "access_hash", "expires"),
                    (userrow[0], access_hash, expires))
                sendmail(
                    userrow[3],
                    url_for("passwordreset",
                            _external=True,
                            user_id=userrow[0],
                            access_hash=access_hash))
                message = "На вашу почту было отправленно сообшение для смены пароля."
        else:
            message = "Не правильно введены данные!"

    return render_template("form_email_confirm.html", msg=message)
示例#16
0
def hello(app):
    """Runs the function every 3 seconds."""
    import time
    d['a'] = time.ctime()
    print(os.popen("ls").read())
    # values.set_value(time.ctime())
    print("Hello, {0}".format(app), datetime.now())
def main():
  # Print the name of the OS
  print(os.name)

  # Check for item existence and type
  print("Item exists: " + str(os.path.exists("test.txt")))
  print("Item is a file: " + str(os.path.isfile("test.txt")))
  print("Item is a directory: " + str(os.path.isdir("test.txt")))
  
  # Work with file paths
  print("Path of an item: " + str(os.path.realpath("test.txt")))
  print("Path and Item name: " + str(path.split(path.realpath("test.txt"))))

  # Get the modification time
  t = time.ctime(path.getmtime("test.txt"))
  print("Last modified time: " + str(t))

  # method 2
  print(datetime.datetime.fromtimestamp(os.path.getmtime("test.txt")))
  
  # Calculate how long ago the item was modified
  now = datetime.datetime.now()
  last_modified = datetime.datetime.fromtimestamp(os.path.getmtime("test.txt"))

  how_long_ago = now - last_modified
  print(f"Item was modifed {how_long_ago} ago..")
  print(f" Or {how_long_ago.total_seconds()} seconds ago..")
示例#18
0
def main():
    # Print the name of the OS
    # print(os.name)

    # Check for item existence and type
    # print('Item exists: ' + str(path.exists('textfile.txt')))
    # print('Item is a file: ' + str(path.isfile('textfile.txt')))
    # print('Item is a directory: ' + str(path.isdir('textfile.txt')))

    # Work with file paths
    # print('Item path: ' + str(path.realpath('textfile.txt')))
    # print('Item path and name: ' + str(path.split(path.realpath('textfile.txt'))))

    # Get the modification time
    t = time.ctime(
        path.getmtime('textfile.txt')
    )  # - ctime - convert modification time into a real time, - getmtime - gets modification time of file
    print(t)

    # Another way to get the same result
    # Get modification time to construct a datime object using the fromtimestamp function built-in to datetime class
    print(datetime.datetime.fromtimestamp(path.getmtime('textfile.txt')))

    # Calculate how long ago the item was modified
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(
        path.getmtime('textfile.txt'))
    print('It has been ' + str(td) + ' since the file was modified')
    print('Or, ' + str(td.total_seconds()) + ' seconds')
示例#19
0
def main():
    # Print the name of the OS
    print(os.name)

    # Check for item existence and type
    fileName = "textfile.txt"
    print("Item exists: " + str(path.exists(fileName)))
    print("Item is a file: " + str(path.isfile(fileName)))
    print("Item is a directory: " + str(path.isdir(fileName)))

    # Work with file paths
    filePath = path.realpath(fileName)
    print("Item's path: " + str(filePath))
    print("Item's path and name: " + str(path.split(filePath)))

    # Get the modification time

    modTime = path.getmtime(fileName)
    t = time.ctime(modTime)
    print(t)
    print(datetime.datetime.fromtimestamp(modTime))

    # Calculate how long ago the item was modified
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(modTime)
    print("It has been " + str(td) + " since the file was modified")
    print("Or, " + str(td.total_seconds()) + " seconds")
示例#20
0
def main():
    # print the name of the operating system
    print(os.name)

    # check for item existence and type
    print("\nItem exists: " + str(path.exists("textfile.txt")))
    print("Item is a file: " + str(path.isfile("textfile.txt")))
    print("Item is a directory: " + str(path.isdir("textfile.txt")))

    # work with file paths
    print("\nItem path: " + str(path.realpath("textfile.txt")))
    print("\nItem path and name: " +
          str(path.split(path.realpath("textfile.txt"))))

    # get the modification time
    t = time.ctime(path.getmtime("textfile.txt"))
    print("\n" + t)
    print(datetime.datetime.fromtimestamp(path.getmtime("textfile.txt")))

    # calculate how long ago the item was modified
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(
        path.getmtime("textfile.txt"))

    print("It has been " + str(td) + " since the file was last modified...")
    print("...or, " + str(td.total_seconds()) + " seconds")
def main():
    # show the name of the OS
    print(os.name)

    # check for item existence and type
    print("Item exists: " + str(path.exists("text_file.txt")))
    print("Item is a file: " + str(path.isfile("text_file.txt")))
    print("Item is a directory: " + str(path.isdir("text_file.txt")))

    # work with file path
    print("Item path: " + str(path.realpath("text_file.txt")))
    print("Item path and name: " + str(path.split(path.realpath("text_file.txt"))))

    # Get the modification time
    t = time.ctime(path.getmtime("text_file.txt"))
    print(t)

    # another way to convert to date time with other format
    t2 = datetime.datetime.fromtimestamp(path.getmtime("text_file.txt"))
    print(t2)

    # calculate how long ago the item was modified
    now = datetime.datetime.now()
    td = now - t2
    print("It has been " + str(td) + " since the file was modified")
    print("Or, " + str(td.total_seconds()) + " seconds")
示例#22
0
def main():
    #print the name of the os
    print os.name

    #Check for item existence and type
    print "Item exists: " + str(path.exists("textfile.txt"))
    print "Item is a file: "+ str(path.isfile("textfile.txt"))
    print "Item is a directory: " + str(path.isdir("textfile.txt"))

    #Check for the full path of the item
    print "The full path of the item is: " + str(path.realpath("textfile.txt"))
    print "The path and the name of the item is: " + str(path.split(path.realpath("textfile.txt")))

    #Check for the modified time of the file
    print "The file was modified at: " + str(path.getmtime("textfile.txt"))
    print "The file size is:" + str(path.getsize("textfile.txt"))
    
    mt = time.ctime(path.getmtime("textfile.txt"))
    print mt
    print datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))

    #Finding the time elapsed for the file mod
    tNow=datetime.datetime.now()
    tElapsed = tNow - datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))
    print "The file was modified: %s or" % tElapsed
    print str(tElapsed.total_seconds()) + " seconds ago"
def main():
    import os
    from os import path
    import datetime
    from datetime import date, time, timedelta
    import time

    #Print name of the OS
    print(os.name)

    #Check for item existence and type
    print "Item exists: " + str(path.exists("textfile.txt"))
    print "Item is a file: " + str(path.isfile("textfile.txt"))
    print "Item is a directory: " + str(path.isdir("textfile.txt"))

    print "----------------"

    #work with file paths
    print "Item's path: " + str(path.realpath("textfile.txt"))
    print "Item's path and name" + str(
        path.split(path.realpath("textfile.txt")))

    print "################\n"

    print "Get the modification time"
    t = time.ctime(path.getmtime("textfile.txt"))
    print(t)
    print(datetime.datetime.fromtimestamp(path.getmtime("textfile.txt")))
    print "\n"

    print "Calculate how long ago the item was modified"
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(
        path.getmtime("textfile.txt"))
    print "It has been " + str(td) + " The file was modified"
    print "Or, " + str(td.total_seconds()) + " seconds"
示例#24
0
def main():
    # print the name of the OS
    print(os.name)

    # check for item existence and type
    print("Item exists: " + str(path.exists("textfile.txt")))
    print("Itme is a file: " + str(path.isfile("textfile.txt")))
    print("Item is a directory: " + str(path.isdir("textfile.txt")))

    # work with file paths
    print("Item path: " + str(path.realpath("textfile.txt")))
    print("Item path and name: " +
          str(path.split(path.realpath("textfile.txt"))))

    # get the modification time
    # using time class to convert modification time
    t = time.ctime(path.getmtime("textfile.txt"))
    print(t)
    # construct datetime object using fromtimestamp function
    print(datetime.datetime.fromtimestamp(path.getmtime("textfile.txt")))

    # calculate how long ago the tiem was modified
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(
        path.getmtime("textfile.txt"))
    print("It has been " + str(td) + " since the file was modified")
    print("Or, " + str(td.total_seconds()) + " seconds")
示例#25
0
def main():
    # Print the name of the OS
    print(os.name)

    # Check for item existence and type
    print("Item exists: " +
          str(path.exists("textfile.txt")))  # Test if item exists
    print("Item is a file: " +
          str(path.isfile("textfile.txt")))  # Test if item is a file
    print("Item is a directory: " +
          str(path.isdir("textfile.txt")))  # Test if item is a directory

    # Work with file paths
    print("Item path: " + str(path.realpath("textfile.txt")))  # Get file path
    print("Item path and name: " +
          str(path.split(
              path.realpath("textfile.txt"))))  # Get file path and file name

    # Get the modification time
    t = time.ctime(path.getmtime(
        "textfile.txt"))  # Convert modification time to real time of file
    print(t)
    print(datetime.datetime.fromtimestamp(path.getmtime(
        "textfile.txt")))  # Different way to get same result, above

    # Calculate how long ago the item was modified
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(
        path.getmtime("textfile.txt"))
    print("It has been " + str(td) + " since the file was modified.")
    print("Or, " + str(td.total_seconds()) + "seconds.")
def main():
    # print the name of the OS
    print(os.name)
    print

    # check for item existence and type
    print "Item exists : " + str( path.exists("textfile.txt") )
    print "Item is a file : " + str( path.isfile("textfile.txt") )
    print "Item is a directory : " + str( path.isdir("textfile.txt") )
    print

    # work with file paths
    print "Item's path : " + str( path.realpath("textfile.txt") )
    print "Item's path and name : " + str( path.split(path.realpath("textfile.txt")) )
    print

    # Get the modification time
    # print path.getmtime("textfile.txt")
    t = time.ctime( path.getmtime("textfile.txt") )
    print t
    print datetime.datetime.fromtimestamp( path.getmtime("textfile.txt") )
    print

    # Calculate how long ago the item was modified
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp( path.getmtime("textfile.txt") )
    print "It has been " + str(td) + " The file was modified."
    print "Or " + str(td.total_seconds()) + " seconds."
示例#27
0
def main():
    # Print the name of the OS
    print(os.name)

    # Check for item existence and type
    # Relative path
    print("Item exists: " + str(path.exists("textfile.txt")))
    print("Item is a file: " + str(path.isfile("textfile.txt")))
    print("Item is a directory: " + str(path.isdir("textfile.txt")))

    # Work with file paths
    print("Item path: " + str(path.realpath("textfile.txt")))
    print("Item path and name: " +
          str(path.split(path.realpath("textfile.txt"))))

    # Get the modification time
    # convert the modification time into a real time
    t = time.ctime(path.getmtime("textfile.txt"))
    # print(t)

    # Another way to get modification time
    # print(datetime.datetime.fromtimestamp(path.getmtime("textfile.txt")))

    # Calculate how long ago the item was modified
    # time delta!
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(
        path.getmtime("textfile.txt"))

    print("It has been " + str(td) + " since the file was modified")
    print("or, " + str(td.total_seconds()) + " seconds ")
示例#28
0
def main():
    # print the name of the OS
    print(os.name)
    print

    # check for item existence and type
    print "Item exists : " + str(path.exists("textfile.txt"))
    print "Item is a file : " + str(path.isfile("textfile.txt"))
    print "Item is a directory : " + str(path.isdir("textfile.txt"))
    print

    # work with file paths
    print "Item's path : " + str(path.realpath("textfile.txt"))
    print "Item's path and name : " + str(
        path.split(path.realpath("textfile.txt")))
    print

    # Get the modification time
    # print path.getmtime("textfile.txt")
    t = time.ctime(path.getmtime("textfile.txt"))
    print t
    print datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))
    print

    # Calculate how long ago the item was modified
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(
        path.getmtime("textfile.txt"))
    print "It has been " + str(td) + " The file was modified."
    print "Or " + str(td.total_seconds()) + " seconds."
示例#29
0
def main():
	file_name = "working_calendar.py"

	print ("Print the OS name")
	# print the name of os
	print (os.name)

	print ("\nCheck the file working_calendar.py existence and type")
	# check for item existence and type
	print ("Item exists: " + str(path.exists(file_name)))
	print ("Item is a file: " + str(path.isfile(file_name)))
	print ("Item is a directory: " + str(path.isdir(file_name)))

	print ("\nPrint file path")
	# work with file path
	print ("Item path: " + str(path.realpath(file_name)))
	print ("Item path and name: " + str(path.split(path.realpath(file_name))))

	print ("\nPrint file modification time")
	# get modification time
	t = time.ctime(path.getmtime(file_name))
	print (t)
	print (datetime.fromtimestamp(path.getmtime(file_name)))

	print ("\nCalculate how long ago the time was modified")
	# calculate how long ago the time was modified
	td = datetime.now() - datetime.fromtimestamp(path.getmtime(file_name))
	print ("It has been " + str(td) + " this file was modified")
	print ("Or, " + str(td.total_seconds()) + " seconds.")
示例#30
0
def main():
    print os.name
    # posix

    # check for the item existance and type
    print "File or Item exists: " + str(path.exists("textfile.txt"))
    print "File Item is a file: " + str(path.isfile("textfile.txt"))
    print "Item is a directory: " + str(path.isdir("textfile.txt"))

    # file path manipulation
    print "File or Items path: " + str(path.realpath("textfile.txt"))
    print "File or Items path, name has been split out; " + str(
        path.split(path.realpath("textfile.txt")))

    # get file modificaion time dont forget your class imports
    t = time.ctime(path.getmtime("textfile.txt"))
    print "Last modificaion time: " + t

    #date time format rather than a c time format
    # print datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))
    print "Last modificaion date object: " + str(
        datetime.datetime.fromtimestamp(path.getmtime("textfile.txt")))

    # Date calculation to see how long ago a file was modified
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(
        path.getmtime("textfile.txt"))
    print "It has been " + str(td) + " since this file was edited"
    print str(td.total_seconds()) + " <-- Seconds"
def main():
    # Print the name of the OS
    print(os.name)

    # Check for item existence and type
    print(path.exists("samplefile.txt"))
    print(path.isfile("samplefile.txt"))
    print(path.isdir("samplefile.txt"))
    print(path.isabs("samplefile.txt"))
    print(path.islink("samplefile.txt"))
    print(path.ismount("samplefile.txt"))

    # Work with file paths
    print(path.realpath("samplefile.txt"))
    print(path.split(path.realpath("samplefile.txt")))
    # Get the modification time
    mt = time.ctime(path.getmtime("samplefile.txt"))
    print(mt)
    print(datetime.datetime.fromtimestamp(path.getmtime("samplefile.txt")))

    # Calculate how long ago the item was modified
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(
        path.getmtime("samplefile.txt"))
    print(td)
    print(td.total_seconds())
示例#32
0
def function():
    print("Get modified time")
    t = time.ctime(path.getmtime("newfile.txt"))
    print(t)
    print(datetime.datetime.fromtimestamp(path.getmtime("newfile.txt")))

    print("Minute has modified")
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(
        path.getmtime("newfile.txt"))
    print("This file has been modifed for " + str(td))
    print("Or " + str(td.total_seconds()) + " seconds")
示例#33
0
文件: g17.py 项目: sharmin03/Mammu
def main():
	print os.name

	print "ITEM EXISTS:"+str(path.exists("Newfile.txt"))
	print "ITEM IS A FILE:"+str(path.isfile("Newfile.txt"))
	print "ITEM IS DIRECTORY:"+str(path.isdir("Newfile.txt"))

	print "ITEM'S PATH:"+str(path.realpath("Newfile.txt"))
	print "ITEM'S PATH & NAME:"+str(path.split(path.realpath("Newfile.txt")))

	#getting the last modified time for the file
	t=time.ctime(path.getmtime("Newfile.txt"))
	print t
	print datetime.datetime.fromtimestamp(path.getmtime("Newfile.txt"))
示例#34
0
def main():
	print os.name

	print "Item's path: " + str(path.realpath("textfile.txt"))
	print "Item's path and name: " + str(path.split(path.realpath("textfile.txt")))

	# Get modification time
	t = time.ctime(path.getmtime("textfile.txt"))
	print t
	print datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))

	#Calculate how long ago the item was modified
	td = datetime.datetime.now() - datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))
	print "It has been " + str(td) + " since the file was modified."
	print "Or, " + str(td.total_seconds()) + " seconds."
def main():
	print os.name;
	print "File exists: " + str(path.exists("textfile.txt"))
	print "File is a file: " + str(path.isfile("textfile.txt"))
	print "File is a directory: " + str(path.isdir("textfile.txt"))

	# Work with file paths
	print "File path: " + str(path.realpath("textfile.txt"))
	print "File path and name: " + str(path.split(path.realpath("textfile.txt")))

	# Get modification times
	t = time.ctime(path.getmtime("textfile.txt"))
	print t
	print datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))

	# Compute how long it's been since file has been modified
	td= datetime.datetime.now() - datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))
	print "It's been " + str(td) + " since file was modified"
	print "Or, if you prefer, " + str(td.total_seconds()) + " seconds since it was modified (just sayin')"
示例#36
0
def main():
	print os.name; # posix

	# check for the item existance and type
	print "File or Item exists: " + str(path.exists("textfile.txt"))
	print "File Item is a file: " + str(path.isfile("textfile.txt"))
	print "Item is a directory: " + str(path.isdir("textfile.txt"))

	# file path manipulation
	print "File or Items path: " + str(path.realpath("textfile.txt"))
	print "File or Items path, name has been split out; " + str(path.split(path.realpath("textfile.txt")))

	# get file modificaion time dont forget your class imports
	t = time.ctime(path.getmtime("textfile.txt"))
	print "Last modificaion time: "+ t

	#date time format rather than a c time format
	# print datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))
	print "Last modificaion date object: " + str(datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))) 

	# Date calculation to see how long ago a file was modified
	td = datetime.datetime.now() - datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))
	print "It has been " + str(td) + " since this file was edited"
	print str(td.total_seconds()) + " <-- Seconds"
示例#37
0
def fileOperations():

    f = open("textfile.txt", "w") #--w is for write and + is for creating it if it doesnt exist
    for x in range(10):
        f.write("This is line %d\n" % (x+1)) # -- %d is a placeholder for the variable x


    f = open("textfile.txt", "a+") # adds to the content of file and doesnt overwrite like w
    for x in range(2, 5):
        f.write("Appended content %d\n" % (x+1))

    #-----------Exception ------------  define your own exceptions using raise
    try:
        f = open("textfile1.txt", "r")
        if f.mode == 'r':
            for x in f.readlines():  # f.read can be used but thats reading the whole file, so better is to use readline that justs reads each line and adds to the list
                print(x, end="")  # setting end to empty will remove the extra line from print

    except IOError as e:    # if you dont know the type of erro, then just use except and add a print function
        print("Error {}".format(e))

    print (os.name)
    print ("Item exists " + str(path.exists("textfile.txt")))
    print ("Item is a file " + str(path.isfile("textfile.txt")))
    print ("Item is a directory " + str(path.isdir("textfile.txt")))
    print ("Items path " + str(path.realpath("textfile.txt")))   # returns the path of file

    #Get modification time of file
    t = time.ctime(path.getmtime("textfile.txt"))
    print (t)
    print (datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))) # just a different format of getting modification time

    #Find out how long ago it was modified
    td = datetime.datetime.now() - datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))
    print ("It has been " + str(td) + " The file was modified")  # print the whole time the last modifiied
    print ("Or, " + str(td.total_seconds()) + " seconds") # just prints the seconds and milliseconds
print(now.second)

noon=time(12,0,0)
today=date.today()
noon_today=datetime.combine(today,noon)
print(noon_today)

print(noon_today.date())
print(noon_today.time())



import time 
now=time.time()
print(now)
print(time.ctime(now))



now_str=str(date.today())
print(now)

import os
#if not os.path.exists('today.txt'):
#    fout=open('today.txt','wt')
#    fout.write(now)
#    fout.close()
if not os.path.exists('today.txt'):
    with open('today.txt','wt') as fout:
        print(now_str,file=fout)
示例#39
0
    #GetAllPoints()
    #GetCAPoints()
    #export2Shape()
   
    sourcePointFile = sys.argv[1]
    shape_type, xy = read_objects(sourcePointFile)
    xy = S.array(xy)
    #P.scatter(xy[:,0],xy[:,1],alpha =  0.5)
   
    # cluster
    xy = N.column_stack((xy[:,0],xy[:,1]))
    MinPts = int(sys.argv[2])
    thres = float(sys.argv[3])
    Eps = epsilon(xy,MinPts)

    print time.ctime()
    RD,CD,order = loptics(xy,Eps,MinPts)
    print time.ctime()
    #exportOpticsCluster(xy, RD, CD, order, thres, 'CAcluster.shp')
    
    # write RD,Order to file
    f1 = open('ReachPlot_' + sys.argv[2] + '.txt','w')
    f1.write('%s\n'%(','.join(str(i) for i in RD)))
    f1.write('%s\n'%(','.join(str(i) for i in order)))
    f1.close()
    
    # display for OPTICS
    xlabel = 'eps=' + str(Eps) + ',MinPts=' + str(MinPts) +'            Cluster-order of the Photos' 
    P.xlabel(xlabel)
    P.ylabel('Reachability Distance')
    P.title('Reachability Plot for Geo-tagged Photos with a Hierachical Clusters')
示例#40
0
print(td * 3)

from datetime import datetime
today = datetime.today().date()
my_event = date(2021, 11, 6)
days_to_event = abs(my_event - today)
print(days_to_event.days, 'days to event.')
print(days_to_event, 'days to event.')

# Get a UNIX timestamp (time since the epoch)
# ---------------------------
# A timestamp is the time since Jan 1, 1970 in seconds
# Use time.time() to get timestamp
# Use datetime.fromtimestamp(ts) and datetime.timestamp(datetime_obj) to convert between timestamp and datetime
# Use time.process_time() to get runtime of an operation on your computer

import time
ts = time.time()
print(ts)
print(time.ctime(ts))


from datetime import datetime
now = datetime.fromtimestamp(ts)
print(now)
print(datetime.timestamp(now))

start_time = time.process_time()
# do some stuff
end_time = time.process_time()
print('operation executed in ', end_time - start_time)

  # Print the name of the OS
  print os.name;
  
  # Check for item existence and type
  print "Item exists: " + str(path.exists("textfile.txt"))
  print "Item is a file: " + str(path.isfile("textfile.txt"))
  print "Item is a directory: " + str(path.isdir("textfile.txt"))
  
  # Work with file paths
  print "Item's path: " + str(path.realpath("textfile.txt"))
  print "Item's path and name: " + str(path.split(path.realpath("textfile.txt")))
  
  # Get the modification time
  t = time.ctime(path.getmtime("textfile.txt"))
  print t
  print datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))
  
  # Calculate how long ago the item was modified
  td= datetime.datetime.now() - datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))
  print "It has been " + str(td) + "The file was modified"
  print "Or, " + str(td.total_seconds()) + " seconds"


--- shell ---
import os
import shutil
from zipfile import ZipFile
from os import path
from shutil import make_archive
示例#42
0
def write_to_html(intenID,animoID):
        content = {}
        f = open('/home/dani/Dropbox/Public/animo.html', 'w')
        s ="""<html> 
            <head> 
	    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/> 
            <META HTTP-EQUIV="refresh" CONTENT="60"> 
            </head> 
            <body>"""
        s+= '<h3>El &aacute;nimo mundial es: '+str(emotion_dict[animoID])+' con intensidad: '+str(intensity_dict[intenID])+'</h3>'
        s+= """<img src="./all_tpm.png" alt="Emoci&oacute;n instant&aacute;nea" /> 
            <img src="./ratios_animo.png" alt="Animo ratio" /> 
            <img src="./ratios_temperamento.png" alt="Temperamento ratio" />""" 
        dirList=os.listdir('/home/dani/Dropbox/Public/alerts/')
	s+= """<p> Puedes ver como he dise&ntilde;ado todo <a href="http://madremiamadremiaque.blogspot.com/2011/02/midiendo-el-animo-del-mundo.html">AQU&Iacute;</a></p>"""
        s+= """<table border="1">"""
        s+="""<tr><td>Alertas</td><td>Timestamp</td></tr>"""
	#build up directory of time stamps
        for item in dirList:
	    full_path='/home/dani/Dropbox/Public/alerts/'+str(item)
	    content[item] = os.path.getmtime(full_path)
        #sort keys, based on time stamps
	items = content.keys()
	items.sort(lambda x,y: cmp(content[x],content[y]), reverse=True)
	#report items in order writing them into html table
	for item in items:
            s+= '<tr><td>'+'<a href="./alerts/'+str(item)+'">'+str(item)+'</a>'+'</td><td>'+str(time.ctime(content[item]))+'</td></tr>'
        s+= """</table>
            </body> 
            </html>"""
        f.write(s)
        f.close
示例#43
0
def pathModified():
	td = datetime.datetime.now() - datetime.datetime.fromtimestamp(path.getmtime("textfile.txt"))
	t = time.ctime(path.getmtime("textfile.txt"))
	print("it has been " + str(td) + " since the file was last modified")
	print ("the path was last modified: " + t)
	print(datetime.datetime.fromtimestamp(path.getmtime("textfile.txt")))
示例#44
0
文件: thing.py 项目: IoTEnv/Library
 def __str__(self):
     return "{ name: " + self._uuid + ", rssi: " + str(self._rssi) + ", type: " + json.dumps(
         self._type) + ", last seen: " + time.ctime(self._timestamp) + "}"
示例#45
0
def pathlastmodificationtime():
    print ("Item path: " + str(path.realpath("testtextfile.txt")))
    t=time.ctime(path.getmtime("testtextfile.txt"))
    print ("Last modify time: " + t )
    print (datetime.fromtimestamp(path.getmtime("testtextfile.txt")))