-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsametime.py
More file actions
59 lines (57 loc) · 2.01 KB
/
sametime.py
File metadata and controls
59 lines (57 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
sametime.py
This program opens up a connection to SSH into the cs.appstate.edu
server. It will be utilized to get bee videos from the same time on
different dates.
The main(path, time) function is used to get the audio files
that will be visualized given a certain time desired.
"""
from ftplib import FTP
import getpass
import StringIO
'''
This function opens the connection and gets the files to be parsed.
The path parameter is the directory that has the directories of mp3 files.
The time parameter is the time that you want, in military time.
Ex. 19:50 is 7:50 PM.
'''
def main(path, time):
#Connect to the cs server with the proper credentials.
session = FTP()
session.connect("cs.appstate.edu")
user = raw_input("Type your username.")
passwd = getpass.getpass("Type your password.")
session.login(user, passwd)
#Set the current directory to the one passed in
session.cwd(path)
#Gets the mp3 file for a certain time every day in the passed in directory
count = 1
#Print the total number of .mp3 files that are in the directory,
#and go through them all
print "Total number of files: " + str(len(session.nlst('*-*-*')))
filelist = []
for name in session.nlst('*-*-*'):
session.cwd(name + '/audio')
read = StringIO.StringIO()
print name
try:
for hit in session.nlst('*' + time + '*'):
#session.retrbinary("RETR " + hit, read.write)
#In order to print the data, change print name to
#print read.getvalue()
#print hit
filelist.append(name + '/audio/' + hit)
print "File number: " + str(count)
count += 1
#Close the StringIO
except Exception, e:
print "No file matched in this directory."
read.close()
session.cwd('../../')
print filelist
#Close the FTP connection
session.quit()
print "Done."
if __name__ == "__main__":
import sys
main(sys.argv[1], sys.argv[2])