User:Inge Hoonte/operating system detector: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "<source lang="bash"> #!/usr/bin/python import os print "Content-type: image/jpg" print if "Linux" in os.environ['HTTP_USER_AGENT']: f=open("linux.jpg") print f...")
 
No edit summary
Line 1: Line 1:
I cleaned up the code I did earlier today (see below). Trying to get this to run within the wiki main page... not working.
<source lang="bash">
<source lang="bash">
#!/usr/bin/python
#!/usr/bin/python


Line 18: Line 19:
         f=open("windows.jpg")
         f=open("windows.jpg")
         print f.read()
         print f.read()
</source>
<source lang="bash">
#!/usr/bin/python
print "Content-type: text/html"
print
import os
#print os.environ
#for key in os.environ:
#      print key,":", os.environ[key], "<br>"
if "Linux" in os.environ['HTTP_USER_AGENT']:
        print """
<html>
<head>
<title>Index</title>
</head>
<body>
<img src="http://linuxnov.com/wp-content/uploads/2011/01/Screenshot-16.png">
<br>
<b style="font family: Arial;font-size: 12px">Welcome home, Linux User</$
<br>
"""
elif "Mac" in os.environ['HTTP_USER_AGENT']:
        print """
<html>
<head>
<title>Index</title>
</head>
<body>
<img src="http://emulators.com/images/GemX_After_Drag.gif">
<br>
<b style="font family: Arial;font size:12px">Welcome, Mac User :)<br/>
<br>
"""
elif "Windows" in os.environ['HTTP_USER_AGENT']:
        print """
<html>
<head>
<body>
<img src="http://www.plig.org/xwinman/screenshots/olwm.gif">
<br>
<b style="font family: Arial; font-size:12px">Welcome home, Windows User<
</body>
</head>
</html>
"""
print """
<ul>
<li><a href="../Lesson One.html">Lesson One</a></li>
<li><a href="../Lesson two.html">Lesson Two</a></li>
<li><a href="../Lesson_03.html">Lesson Three</a></li>
<li><a href="../Lesson_04.html">Lesson Four</a></li>
</ul>
</body>
</html>
"
</source>
</source>

Revision as of 00:50, 4 November 2011

I cleaned up the code I did earlier today (see below). Trying to get this to run within the wiki main page... not working.

#!/usr/bin/python

import os
print "Content-type: image/jpg"
print

if "Linux" in os.environ['HTTP_USER_AGENT']:
        f=open("linux.jpg")
        print f.read()

elif "Mac" in os.environ['HTTP_USER_AGENT']:
        f=open("mac.jpg")
        print f.read()

elif "Windows" in os.environ['HTTP_USER_AGENT']:
        f=open("windows.jpg")
        print f.read()


#!/usr/bin/python

print "Content-type: text/html"
print

import os
#print os.environ

#for key in os.environ:
#       print key,":", os.environ[key], "<br>"

if "Linux" in os.environ['HTTP_USER_AGENT']:
        print """
<html>
<head>
<title>Index</title>
</head>
<body>
<img src="http://linuxnov.com/wp-content/uploads/2011/01/Screenshot-16.png">
<br>
<b style="font family: Arial;font-size: 12px">Welcome home, Linux User</$
<br>
"""
elif "Mac" in os.environ['HTTP_USER_AGENT']:
        print """
<html>
<head>
<title>Index</title>
</head>
<body>
<img src="http://emulators.com/images/GemX_After_Drag.gif">
<br>

<b style="font family: Arial;font size:12px">Welcome, Mac User :)<br/>
<br>
"""
elif "Windows" in os.environ['HTTP_USER_AGENT']:
        print """
<html>
<head>
<body>
<img src="http://www.plig.org/xwinman/screenshots/olwm.gif">
<br>
<b style="font family: Arial; font-size:12px">Welcome home, Windows User<
</body>
</head>
</html>

"""

print """
<ul>
<li><a href="../Lesson One.html">Lesson One</a></li>
<li><a href="../Lesson two.html">Lesson Two</a></li>
<li><a href="../Lesson_03.html">Lesson Three</a></li>
<li><a href="../Lesson_04.html">Lesson Four</a></li>
</ul>
</body>
</html>
"