1

Ok so The script is now working, Id like to thank all for the advice.

heres the final script

import smtplib 
import xbmc
import xbmcgui
import datetime

list = ("mary", "james", "tilly")

kb = xbmc.Keyboard('', 'Please type in your name to continue')
kb.doModal()
typedin = kb.getText()

if typedin.lower() in list:
    now = datetime.datetime.now()
    runtime = now.strftime("%Y-%m-%d %H:%M")

    content = xbmc.executebuiltin('kb.getText()')
    mailserver = smtplib.SMTP("smtp.mail.com",25)
    mailserver.ehlo()
    mailserver.starttls()
    mailserver.login('mail@somemail.com','somepwd')
    mailserver.sendmail('mail@somemail.com','mail@somemail.com',typedin + ' has run proggy ' + runtime)
    mailserver.close()
    xbmc.executebuiltin("Notification(An email has been sent, yada yada yada,()")
else:
    xbmc.executebuiltin("THE INPUTTED NAME, IS NOT VALID,()")
    xbmcgui.Dialog().ok(
    "Please try again - User name not correct",
    "The input yada yada",
    "yada yada",
    "yada yada")

So, just to let you know that im using live mail which works on port 25. Tried and tested on both windows and linux and openelec. Working fine.

Simon Jeal
  • 153
  • 2
  • 4
  • 14
  • What do you want to happen when the user input is not in the list? –  Jul 25 '15 at 14:44
  • for the moment is just to exit out using else: xbmc.executebuiltin("Notification(Name is not in list, exiting,()") xbmc.executebuiltin("ActivateWindow(10000,return)") – Simon Jeal Jul 25 '15 at 15:03
  • xbmc.executebuiltin("The Name you have used, was not in the list,()" is already on the bottom of the code, but not running if the names do not match. – Simon Jeal Jul 25 '15 at 15:11
  • I don't have those things installed so cant test it, but how about instead of the else an 'if tpyedin.lower() not in str1:' –  Jul 25 '15 at 15:13

3 Answers3

3

Maybe something along the lines of an if statement? So only if one of these words are given, then do the rest, otherwise do not accept.

list = ["simon", "tom", "sarah", "peter", "jane"]
word = input()
if word.lower() in list:
    print('Ok')
    #continue with rest of program
else:
     print('No, sorry')
1

The best to do in a situation where one wishes to grab input from a user is to do a while loop with a raw_input statement like:

word_list = ['simon', 'tom', 'sarah', 'peter', 'jane', 'sue']

def get_word():
    """returns the word that the user chooses"""
    print("Please choose a name from the following:")
    w_string = ""
    for w in word_list:
        w_string += w + ', '
    #print the word list without a comma at the end.
    print(w_string[:-1])

    while True:
        word = raw_input("\n> ") #use input("\n> ") for python3
        #If you wish to accept something like "SiMoN      " or "S Imon "
        #have the following line:
        word = word.lower().strip()
        if word in word_list:
            return word
        else:
            print("'%s' is not in the list of words. Please choose from the following:\n%s" % (word, w_string[:-1]))

word = get_word()
print(word)
  • I have edited the script showing the progress. 50% working now. More Info at the bottom of first post. Thanks for your help – Simon Jeal Jul 25 '15 at 13:07
  • xbmc.executebuiltin("The Name you have used, was not in the list,()" does not look right. I don't know why you're not using print, but what I think this should look like is: xbmc.executebuiltin("The Name you have used, was not in the list") – Brandon Keith Biggs Jul 26 '15 at 00:23
  • Pasted the final code. Thanks to all for the advice. Solved – Simon Jeal Jul 27 '15 at 15:36
0

I the best option would me not to covert the list to string and check if the entered name is in the list like..

import smtplib
import xbmc
import xbmcgui
import datetime

nameList = ["simon", "tom", "sarah", "peter", "jane"]
kb = raw_input('Please type in your name to continue:')

if kb in nameList:
    now = datetime.datetime.now()
    runtime = now.strftime("%Y-%m-%d %H:%M")

    content = xbmc.executebuiltin('kb.getText()')
    mailserver = smtplib.SMTP("smtp.mail.com",25)
    mailserver.ehlo()
    mailserver.starttls()
    mailserver.login('mail@somemail.com','somepwd')
    mailserver.sendmail('mail@somemail.com','mail@somemail.com',typedin + 'has run keymail ' + runtime)
    mailserver.close()
else:
    print ("The Name %s, was not in the list")%kb

and dont use list and str as a variable names.

Sujay Narayanan
  • 487
  • 4
  • 11