Greet user based on system time - RMB Scripting
You appear not to have an account with us, Click HERE to register an account...
RMB Scripting
Navigation
  Home
  Contact
  FAQ
  Forum
  Topsites
  Members
  Affiliates
  Arcade <-- New!
  IoxHost
Downloads
  Templates
  Scripts
  Fonts
  Image Sets
  Software
  Other
 
Tutorials
  .htaccess
  Photoshop
  C/C++
  CSS
  Macromedia Flash
  MySQL
  PHP
  PHP - User System
  HTML
  Javascript
  Macintosh
  Macromedia Fireworks
  Visual Basic
  Visual C#
  Windows
  Python
  Other
 
Latest Tutorials
Get the date of every ...
If...Else on one line ...
Drop Calendar Function
Single VS Double
Understanding Variables
Latest Comments
Simple Comment System
Simple Comment System
Simple Comment System
Simple Comment System
Private Message System
Stats
Total Members: 585 [231]
Total Tutorials: 276
Newsest User: zaithstery
Todays Unique Hits: 71
Users Online: 0
 
8 Guests
Poll
Should we change our name?
Hmmmm, Yes!!
Maybe
Depends on what to
NO!
Main Content
Tutorial: Greet user based on system time By ShadowMage
To start off we need to import 3 libraries. The os, sys, and time.
   
CODE:
import os
import sys
import time


Those three libraries are the core libraries which will run the script.

Now, this also includes what we did from the "Get logged on user" tutorial.

   
CODE:
sysHour = time.strftime("%H") #get the current military hour
if sys.platform == 'win32': #Time for cross-platform
userName = os.getenv('USERNAME') #windows
else:
userName = os.getenv('USER') #linux and others.

if sysHour >= 0 and sysHour < 12: #12am until 12pm
print "Good morning, " + userName + "."
elif sysHour >= 12 and sysHour < 18: #12pm to 6pm
print "Good afternoon, " + userName + "."
else:
print "Good evening, " + userName + "." #The hour is later then 6pm



The if statement at the top,
   
CODE:
if sys.platform == 'win32': #Time for cross-platform
userName = os.getenv('USERNAME') #windows
else:
userName = os.getenv('USER') #linux and others.



will check the system's platform, then get the environmental variable for the username.

The other if statement,
   
CODE:
if sysHour >= 0 and sysHour < 12: #12am until 12pm
print "Good morning, " + userName + "."
elif sysHour >= 12 and sysHour < 18: #12pm to 6pm
print "Good afternoon, " + userName + "."
else:
print "Good evening, " + userName + "." #The hour is later then 6pm



Will check the hour for the time then greet the user.

Hope you learned something from this brief tutorial

Note: The python files must end with a blank line or you will get an error.
Difficulty: Easy
Views: 522
Rating:
Comments
There are currently no comments for this tutorial.
Notice:
Remember to post long codes on our pastbin! - (http://rmb.pastebin.com/)
Add Comment
You must be logged in to post a comment.
Good Morning Guest
Username: 
Password: 
Remember Username
Links
RMB Arcade
$2.50 Resellers
Free Domains
Free Games
Affiliates