The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
finding who's online
Discuss finding who's online in the Python Programming forum on Dev Shed. finding who's online Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 6th, 2003, 08:56 AM
|
 |
action=(isSleep())?sleep:code;
|
|
Join Date: Oct 2003
Location: Sydney->Indiana
Posts: 182
  
Time spent in forums: 15 h 8 m 29 sec
Reputation Power: 14
|
|
finding who's online
I've seen this question and quite a few answers in PHP and I'm getting some ideas for doing it in python. That is finding out who's online at any particular time on a particular webpage.
I'm guessing I'll be using some kind of temp file and the os.environ["REMOTE_ADDR"]
function, but I was wondering if anybody had any ideas or snippets of success before?
Thanks,
Benjamin
|

October 7th, 2003, 07:39 PM
|
|
Contributing User
|
|
Join Date: Dec 2001
Location: Houston, TX
Posts: 383
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 12
|
|
|
"online at any particular time on a particular webpage"? You mean like on here? The only real way to do it, unless there's some sort of other way to access that data, is to just parse the webpage for it.
|

October 8th, 2003, 02:04 AM
|
 |
action=(isSleep())?sleep:code;
|
|
Join Date: Oct 2003
Location: Sydney->Indiana
Posts: 182
  
Time spent in forums: 15 h 8 m 29 sec
Reputation Power: 14
|
|
|
Yes, online at that particular moment for that webpage, similar to the way devshed's forums have at the bottom user's and who they are. Any ideas?
Thanks,
Benjamin
|

October 8th, 2003, 07:18 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
Surly to get the info your program would have to be on the webserver your tageting.
Quote: | That is finding out who's online at any particular time on a particular webpage |
it's got to be hard if not impossibe to just pick a website and get a list or remote IP's on that page.. maybe you could post a few links to the idea's you were given on how to do it in PHP?
Mark
__________________
programming language development: www.netytan.com – Hula
|

October 8th, 2003, 07:35 AM
|
 |
action=(isSleep())?sleep:code;
|
|
Join Date: Oct 2003
Location: Sydney->Indiana
Posts: 182
  
Time spent in forums: 15 h 8 m 29 sec
Reputation Power: 14
|
|
Sorry should have made that clear, it's for my own site. It's got php, so I could use that, but I'd rather do it in python as not only do I like python more, I've already got python code running.
So yes, I've got access to the server, all the cgi variables and wish to go about doing something like this(php, sorry for the length) get's who's online using files:
PHP Code:
<?php
//vars
$file_name = "data.txt";
$c_time = time();
$timeout = 300;
$time = $c_time - $timeout;
//write to file ip and time
$fp = fopen($file_name, "a");
$write = $REMOTE_ADDR."||".$c_time."\n";
fwrite($fp, $write);
fclose($fp);
//open file into array
$file_array = file($file_name);
$online_array = array();//create online array
foreach($file_array as $data){
list($ip, $user_time) = explode("||", $data);
if($user_time >= $time){
array_push($online_array, $ip);
}//end if
}//end foreach
//count and output data
$online = array_unique($online_array);
$online = count($online);
if($online == "1"){
echo "User online: $online";
}else{
echo "Users online: $online";
}
?>
in python.
Cheers,
Benjamin
|

October 8th, 2003, 10:19 AM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
OK, this should do the same thing! it's untested and could be improved a little but hey
Code:
import os, time
filename = 'data.txt'
timenow = time.time() - 300
online = {}
file(filename, 'a').write(str(os.environ('REMOTE_ADDR')) + '-' + str(time.time()) + '\n')
for user in file(filename, 'r').readlines():
user = user.strip().split('-')
if user[1] >= timenow:
online[user[0]] = user[1]
users = ', '.join(online.keys())
if len(online.keys()) == 1:
print 'User online:', users
else:
print 'Users online:', users
Have fun,
Mark.
Last edited by netytan : October 8th, 2003 at 10:23 AM.
|

October 8th, 2003, 06:43 PM
|
 |
action=(isSleep())?sleep:code;
|
|
Join Date: Oct 2003
Location: Sydney->Indiana
Posts: 182
  
Time spent in forums: 15 h 8 m 29 sec
Reputation Power: 14
|
|
|
Thanks Mark, I'll have a play and check it out.
Cheers,
Benjamin
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|