Releases Script
The script runs each 30 seconds and check for new message,in one of the folders in the mail.
if it finds that new message arrived to the folder
it using the ICQ "Ho-Ho" sound to alert the user.
import win32com.client as win32
import time
import os
class Release:
lastCount = 0
def countReleases(self):
outlook = win32.gencache.EnsureDispatch("Outlook.Application")
mapi = outlook.GetNamespace("MAPI")
inbox = mapi.GetDefaultFolder(win32.constants.olFolderInbox)
releases_foler = inbox.Folders.Item("Releases")
releases_msg = releases_foler.Items
current_Count = releases_msg.Count
if self.lastCount == 0:
print "New Releases: " + str(self.lastCount)
self.lastCount = current_Count
else:
if current_Count > self.lastCount:
print "New Rlease added!!"
print "New Releases: " + str(current_Count - self.lastCount)
else:
print "No new releases"
self.Update()
def Update(self):
print "Next update will be in 30 seconds"
time.sleep(30)
os.system("cls")
time.sleep(0.3)
self.countReleases()
def Main():
r = Release()
r.countReleases()
if __name__ == "__main__":
Main()
Hangman Script
Remember when in free period at school, someone offered you to play hangman.
when he had to hide a word and you had to guess it by guessing its letters,
and if you got wrong he started to drew a man hanging?... I know you remember!
did you enjoyed it? So this is the script for you!
#Import Section
import random
import re
import sys
#Constants
PLAYER_NUM_OF_GUESSES = 12
CATEGORY = {"movies" : ["harry-potter","brigde-of-spies","avengers","captain-america","deadpool","spiderman"],
"fruits" : ["banana","mango","pineapple","orange"],
"countries" : ["israel","egypt","united-state","germany","italy"]}
GAME_MODE = "Whice Category Do You Prefer?\n1. Movies\n2. Fruits\n3. Countries"
DIVIDER = "#########################################\nYou have 12 guesses"
WORD_TO_GUESS = "Word To Guess:\n"
TRY = "\nTry to guess"
TRY_AGAIN = "Please try again."
NEW_LINE = "\n"
THANK = "Thank You For Playing"
GREAT = "\nGreat Job"
WRONG = "\nWrong Guess"
GUESS_CORRECT = "Wow!! You Guessed The Word!"
WELCOME = "Welcome To The Hangman Game!!\nYour Target Is To Guess The Hidden Word" + "\nPay Attention - You Dont Have As Many Guesses As You Want\nHave Fun!"
#Global Variable
count_guess = 0
char_list = ["_"]
#Defining function to check the guesses the user used.
def check_num_of_guesses(count):
if count == PLAYER_NUM_OF_GUESSES:
print "You are out of guesses! Loser!"
return True
return False
#Defining function to initalize the word to guess.
def word_selection():
print GAME_MODE
mode = raw_input("Which One?")
if mode == "1":
com_word = random.choice(CATEGORY["movies"])
elif mode == "2":
com_word = random.choice(CATEGORY["fruits"])
elif mode == "3":
com_word = random.choice(CATEGORY["countries"])
else:
print "Game mode not selected."
sys.exit()
return com_word
#Defining function to check if the user already used the entered char.
def IsUsed(char):
global count_guess
used_char = []
if char == "":
count_guess = count_guess + 1
if check_num_of_guesses(count_guess):
print THANK
else:
print "You Used",count_guess,"Guesses."
elif char in used_char:
print TRY_AGAIN
user_guess = raw_input("Enter char: ")
IsUsed(user_guess)
else:
used_char.append(char)
#Defining function that prompt the hidden list to the user.
def prompt_missing(word_to_guess):
global char_list
char_list = char_list * len(word_to_guess)
print WORD_TO_GUESS
check_for_dash(word_to_guess)
print char_list
#Defining function to verify if the guessed word is correct
def check_word(list):
complete_word = "".join(list)
return complete_word
#Defining function to check for spaces in word and replace with dashes
def check_for_dash(word):
global char_list
if re.search("-+",word):
dash_pos = 0
dash_count = word.count("-")
dash_pos = word.find("-",dash_pos)
char_list[dash_pos] = "-"
while dash_count > 1:
dash_pos = word.find("-", dash_pos + 1)
char_list[dash_pos] = "-"
dash_count = dash_count - 1
#Defining function update_char to check if the char is in the char_list
def update_char(word,user_guess):
global char_list
pos = 0
char_count = word.count(user_guess)
pos = word.index(user_guess,pos)
char_list[pos] = user_guess
while char_count > 1:
pos = word.index(user_guess, pos + 1)
char_list[pos] = user_guess
char_count = char_count - 1
#Defining function to check for char in the missing list
def check_char():
global char_list,count_guess
#Using new_game function
new_game()
#Genrating random word to guess
word_to_guess = word_selection()
#Creating list of chars from the word
hidden_char_list = list(word_to_guess)
#Prompt the chars to complete to the player
prompt_missing(word_to_guess)
user_guess = raw_input("Enter your guess: ")
IsUsed(user_guess)
while count_guess < PLAYER_NUM_OF_GUESSES:
if user_guess in hidden_char_list:
update_char(word_to_guess,user_guess)
new_word = check_word(char_list)
if new_word == word_to_guess:
print NEW_LINE
print GUESS_CORRECT
print char_list
play_again = raw_input("Do you want to play again?")
if play_again.lower() in ["yes","y"]:
check_char()
else:
print THANK
sys.exit()
print NEW_LINE
print char_list
print GREAT
user_guess = raw_input("Enter your guess: ")
IsUsed(user_guess)
else:
print NEW_LINE
print WRONG
print char_list
count_guess = count_guess + 1
if check_num_of_guesses(count_guess):
print "The word is: " + word_to_guess
play_again = raw_input("Do you want to play again?")
if play_again.lower() in ["yes","y"]:
check_char()
else:
print THANK
sys.exit()
print "You Used",count_guess,"Guesses."
user_guess = raw_input("Enter your guess: ")
IsUsed(user_guess)
#Defining function to initalize the variables before game start
def new_game():
global count_guess,char_list
count_guess = 0
char_list = ["_"]
#Defining main function to control the flow of the program
def main():
print WELCOME
print DIVIDER
check_char()
if __name__ == '__main__':
main()
CopyFolders Script
The script purpose is to copy entire folder from one host to another.
The script gets the name of the folder, 2 destinations and list of hosts and get a connection to each one.
while in connection the script check if the folder already exists on the host.
If exists - it deletes the folder and copy it again. Else - you can figure it out :)
import subprocess, os, shutil
flag = "Copied to all!"
global failed
def separate_slots(listwithslots):
j=0
list = []
for i in listwithslots:
list.append([])
list[j].append(i.rpartition(",")[0])
list[j].append(i.rpartition(",")[2])
j=j+1
return list
def delete_folder(full_dst_path):
shutil.rmtree(full_dst_path)
def copy_folder(list,src_path,folder_name,dst_path):
global flag, failed
failed = []
list = separate_slots(list)
lastSetup = None
#Create the full path to the folder - send the folder
folder_path = src_path + "\\" + folder_name
if not os.path.isdir(folder_path):
flag = "Folder doesn't exists"
return flag
#Iterate througe the list to find each setup
for host,slot in list:
if host == lastSetup:
continue
else:
cmd_command = "net use \\\\" + host + "\\c /user:USER PASSWORD"
try:
subprocess.call(cmd_command,creationflags=0x08000000)
print "Connected"
except:
failed.append(host)
continue
full_dst_path = "\\\\" + host + "\\" + dst_path + folder_name
#print "path created"
if os.path.isdir(full_dst_path):
delete_folder(full_dst_path)
try:
shutil.copytree(folder_path,full_dst_path)
#print "Sent"
lastSetup = host
except:
failed.append(host)
continue
else:
#Create the full path to the folder - send the folder
#folder_path = src_path + "\\" + folder_name
try:
shutil.copytree(folder_path,full_dst_path)
#print "Sent"
lastSetup = host
except:
#print "Failed"
failed.append(host)
continue
if len(failed) != 0:
flag = "Failed On: "
for iter in xrange(len(failed)):
flag = flag + failed[iter] + " "
copy_folder(list_of_setups,src_path,folder_name,dst_path)