Skip to content

Commit 0d1f9c3

Browse files
Merge pull request #440 from jinyoungHan/master
Updated to Python 3 this files
2 parents c2fdd74 + 367a0e7 commit 0d1f9c3

File tree

7 files changed

+125
-114
lines changed

7 files changed

+125
-114
lines changed

pscheck.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def ps():
3131
except:
3232
print("There was a problem with the program.")
3333

34-
3534
def main():
3635
if os.name == "posix": # Unix/Linux/MacOS/BSD/etc
3736
ps() # Call the function

psunotify.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
urls[int]=urls[int].replace("<b>","")
2121
urls[int]=urls[int].replace("</b>","")
2222
int=int+1
23+
2324
print(urls)
25+
2426
for url in urls:
2527
try:
2628
temp=url.split("/")
@@ -32,7 +34,7 @@
3234
file=open('psu2'+q+'.pdf','wb')
3335
file.write(r.read())
3436
file.close()
37+
3538
print("Done")
3639
except urllib2.URLError as e:
3740
print("Sorry there exists a problem with this URL Please Download this Manually "+str(url))
38-

python_sms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
response = urllib2.urlopen(req)
7272
response_url = response.geturl()
7373
if response_url == url:
74+
7475
print('SMS sent!')
7576
except urllib2.URLError as e:
7677
print('Send failed!')

recyclebin.py

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,49 @@
11
from __future__ import print_function
2-
# Script Name : recyclebin.py
3-
# Author : Craig Richards
4-
# Created : 07th June 2013
5-
# Last Modified :
6-
# Version : 1.0
7-
8-
# Modifications :
9-
10-
# Description : Scans the recyclebin and displays the files in there, originally got this script from the Violent Python book
11-
12-
import os # Load the Module
13-
import optparse # Load the Module
14-
from _winreg import * # Load the Module
15-
16-
def sid2user(sid): # Start of the function to gather the user
17-
try:
18-
key = OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" + '\\' + sid)
19-
(value, type) = QueryValueEx(key, 'ProfileImagePath')
20-
user = value.split('\\')[-1]
21-
return user
22-
except:
23-
return sid
24-
25-
26-
def returnDir(): # Start of the function to search through the recyclebin
27-
dirs=['c:\\Recycler\\','C:\\Recycled\\','C:\\$RECYCLE.BIN\\']
28-
#dirs=['c:\\$RECYCLE.BIN\\']
29-
for recycleDir in dirs:
30-
if os.path.isdir(recycleDir):
31-
return recycleDir
32-
return None
33-
34-
def findRecycled(recycleDir): # Start of the function, list the contents of the recyclebin
35-
dirList = os.listdir(recycleDir)
36-
for sid in dirList:
37-
files = os.listdir(recycleDir + sid)
38-
user = sid2user(sid)
39-
print('\n[*] Listing Files for User: ' + str(user))
40-
for file in files:
41-
print('[+] Found File: ' + str(file))
42-
43-
def main():
44-
recycleDir = returnDir()
45-
findRecycled(recycleDir)
46-
47-
if __name__ == '__main__':
48-
main()
2+
# Script Name : recyclebin.py
3+
# Author : Craig Richards
4+
# Created : 07th June 2013
5+
# Last Modified :
6+
# Version : 1.0
7+
8+
# Modifications :
9+
10+
# Description : Scans the recyclebin and displays the files in there, originally got this script from the Violent Python book
11+
12+
import os # Load the Module
13+
import optparse # Load the Module
14+
from _winreg import * # Load the Module
15+
16+
def sid2user(sid): # Start of the function to gather the user
17+
try:
18+
key = OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" + '\\' + sid)
19+
(value, type) = QueryValueEx(key, 'ProfileImagePath')
20+
user = value.split('\\')[-1]
21+
return user
22+
except:
23+
return sid
24+
25+
26+
def returnDir(): # Start of the function to search through the recyclebin
27+
dirs=['c:\\Recycler\\','C:\\Recycled\\','C:\\$RECYCLE.BIN\\']
28+
#dirs=['c:\\$RECYCLE.BIN\\']
29+
for recycleDir in dirs:
30+
if os.path.isdir(recycleDir):
31+
return recycleDir
32+
return None
33+
34+
def findRecycled(recycleDir): # Start of the function, list the contents of the recyclebin
35+
dirList = os.listdir(recycleDir)
36+
for sid in dirList:
37+
files = os.listdir(recycleDir + sid)
38+
user = sid2user(sid)
39+
40+
print('\n[*] Listing Files for User: ' + str(user))
41+
for file in files:
42+
print('[+] Found File: ' + str(file))
43+
44+
def main():
45+
recycleDir = returnDir()
46+
findRecycled(recycleDir)
47+
48+
if __name__ == '__main__':
49+
main()

script_count.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def github(): # Start of the function just to count the fil
3434
github_dir = os.path.join(dropbox, 'github') # Joins the paths to get the github directory - 1.1
3535
github_count = sum((len(f) for _, _, f in os.walk(github_dir))) # Get a count for all the files in the directory
3636
if github_count > 5: # If the number of files is greater then 5, then print the following messages
37+
3738
print('\nYou have too many in here, start uploading !!!!!')
3839
print('You have: ' + str(github_count) + ' waiting to be uploaded to github!!')
3940
elif github_count == 0: # Unless the count is 0, then print the following messages
@@ -45,6 +46,7 @@ def development(): # Start of the function just to count the
4546
dev_dir = os.path.join(path, 'development') # Joins the paths to get the development directory - 1.1
4647
dev_count = sum((len(f) for _, _, f in os.walk(dev_dir))) # Get a count for all the files in the directory
4748
if dev_count > 10: # If the number of files is greater then 10, then print the following messages
49+
4850
print('\nYou have too many in here, finish them or delete them !!!!!')
4951
print('You have: ' + str(dev_count) + ' waiting to be finished!!')
5052
elif dev_count ==0: # Unless the count is 0, then print the following messages

sendemail.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ def get_credentials():
2929
flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
3030
flow.user_agent = APPLICATION_NAME
3131
credentials = tools.run_flow(flow, store)
32+
3233
print('Storing credentials to ' + credential_path)
34+
3335
return credentials
3436

3537
def SendMessage(sender, to, subject, msgHtml, msgPlain, attachmentFile=None):
@@ -46,7 +48,9 @@ def SendMessage(sender, to, subject, msgHtml, msgPlain, attachmentFile=None):
4648
def SendMessageInternal(service, user_id, message):
4749
try:
4850
message = (service.users().messages().send(userId=user_id, body=message).execute())
51+
4952
print('Message Id: %s' % message['id'])
53+
5054
return message
5155
except errors.HttpError as error:
5256
print('An error occurred: %s' % error)

spotlight.py

Lines changed: 67 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,68 @@
1-
""" Script To Copy Spotlight(Lockscreen) Images from Windows """
1+
""" Script To Copy Spotlight(Lockscreen) Images from Windows """
22
from __future__ import print_function
3-
import os
4-
import shutil
5-
import errno
6-
import hashlib
7-
from PIL import Image
8-
9-
def md5(fname):
10-
""" Function to return the MD5 Digest of a file """
11-
12-
hash_md5 = hashlib.md5()
13-
with open(fname, "rb") as file_var:
14-
for chunk in iter(lambda: file_var.read(4096), b""):
15-
hash_md5.update(chunk)
16-
return hash_md5.hexdigest()
17-
18-
def make_folder(folder_name):
19-
"""Function to make the required folers"""
20-
try:
21-
os.makedirs(folder_name)
22-
except OSError as exc:
23-
if exc.errno == errno.EEXIST and os.path.isdir(folder_name):
24-
pass
25-
else:
26-
print("Error! Could not create a folder")
27-
raise
28-
29-
def get_spotlight_wallpapers(target_folder):
30-
"""Fetches wallpapers from source folder inside AppData to the
31-
newly created folders in C:\\Users\\['user.name']\\Pictures"""
32-
#PATHS REQUIRED TO FETCH AND STORE WALLPAPERS
33-
#Creating necessary folders
34-
35-
source_folder = os.environ['HOME']+"\\AppData\\Local\\Packages\\"
36-
source_folder += "Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy"
37-
source_folder += "\\LocalState\\Assets"
38-
spotlight_path_mobile = target_folder+"\\Mobile"
39-
spotlight_path_desktop = target_folder+"\\Desktop"
40-
make_folder(spotlight_path_mobile)
41-
make_folder(spotlight_path_desktop)
42-
43-
44-
#Fetching files from the source dir
45-
for filename in os.listdir(source_folder):
46-
filename = source_folder+"\\"+filename
47-
#if size of file is less than 100 KB, ignore the file
48-
if os.stat(filename).st_size > 100000:
49-
#Check resolution and classify based upon the resolution of the images
50-
51-
#name the file equal to the MD5 of the file, so that no duplicate files are to be copied
52-
img_file = Image.open(filename)
53-
if img_file.size[0] >= 1080:
54-
if img_file.size[0] > img_file.size[1]:
55-
temp_path = spotlight_path_desktop+"\\"+md5(filename)
56-
else:
57-
temp_path = spotlight_path_mobile+"\\"+md5(filename)
58-
#If file doesn't exist, copy the file to the new folders
59-
if not os.path.exists(temp_path+".png"):
60-
shutil.copy(filename, temp_path+".png")
61-
62-
if __name__ == '__main__':
63-
PATH = raw_input("Enter directory path:")
64-
get_spotlight_wallpapers(PATH)
65-
print("Lockscreen images have been copied to \""+PATH+"\"")
66-
3+
import os
4+
import shutil
5+
import errno
6+
import hashlib
7+
from PIL import Image
8+
9+
def md5(fname):
10+
""" Function to return the MD5 Digest of a file """
11+
12+
hash_md5 = hashlib.md5()
13+
with open(fname, "rb") as file_var:
14+
for chunk in iter(lambda: file_var.read(4096), b""):
15+
hash_md5.update(chunk)
16+
return hash_md5.hexdigest()
17+
18+
def make_folder(folder_name):
19+
"""Function to make the required folers"""
20+
try:
21+
os.makedirs(folder_name)
22+
except OSError as exc:
23+
if exc.errno == errno.EEXIST and os.path.isdir(folder_name):
24+
pass
25+
else:
26+
print("Error! Could not create a folder")
27+
raise
28+
29+
def get_spotlight_wallpapers(target_folder):
30+
"""Fetches wallpapers from source folder inside AppData to the
31+
newly created folders in C:\\Users\\['user.name']\\Pictures"""
32+
#PATHS REQUIRED TO FETCH AND STORE WALLPAPERS
33+
#Creating necessary folders
34+
35+
source_folder = os.environ['HOME']+"\\AppData\\Local\\Packages\\"
36+
source_folder += "Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy"
37+
source_folder += "\\LocalState\\Assets"
38+
spotlight_path_mobile = target_folder+"\\Mobile"
39+
spotlight_path_desktop = target_folder+"\\Desktop"
40+
make_folder(spotlight_path_mobile)
41+
make_folder(spotlight_path_desktop)
42+
43+
44+
#Fetching files from the source dir
45+
for filename in os.listdir(source_folder):
46+
filename = source_folder+"\\"+filename
47+
#if size of file is less than 100 KB, ignore the file
48+
if os.stat(filename).st_size > 100000:
49+
#Check resolution and classify based upon the resolution of the images
50+
51+
#name the file equal to the MD5 of the file, so that no duplicate files are to be copied
52+
img_file = Image.open(filename)
53+
if img_file.size[0] >= 1080:
54+
if img_file.size[0] > img_file.size[1]:
55+
temp_path = spotlight_path_desktop+"\\"+md5(filename)
56+
else:
57+
temp_path = spotlight_path_mobile+"\\"+md5(filename)
58+
#If file doesn't exist, copy the file to the new folders
59+
if not os.path.exists(temp_path+".png"):
60+
shutil.copy(filename, temp_path+".png")
61+
62+
if __name__ == '__main__':
63+
PATH = raw_input("Enter directory path:")
64+
get_spotlight_wallpapers(PATH)
65+
print("Lockscreen images have been copied to \""+PATH+"\"")
66+
67+
68+

0 commit comments

Comments
 (0)