Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old October 6th, 2003, 08:56 AM
whitelines's Avatar
whitelines whitelines is offline
action=(isSleep())?sleep:code;
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Sydney->Indiana
Posts: 182 whitelines User rank is Corporal (100 - 500 Reputation Level)whitelines User rank is Corporal (100 - 500 Reputation Level)whitelines User rank is Corporal (100 - 500 Reputation Level)whitelines User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 15 h 8 m 29 sec
Reputation Power: 9
Question 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
__________________
/*
* www.benjaminranck.com
* bjamins.blogspot.com
*/

Reply With Quote
  #2  
Old October 7th, 2003, 07:39 PM
Strike Strike is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2001
Location: Houston, TX
Posts: 383 Strike User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 7
Send a message via ICQ to Strike Send a message via AIM to Strike Send a message via Yahoo to Strike
"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.
__________________
Debian - because life's too short for worrying.
Best. (Python.) IRC bot. ever.

Reply With Quote
  #3  
Old October 8th, 2003, 02:04 AM
whitelines's Avatar
whitelines whitelines is offline
action=(isSleep())?sleep:code;
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Sydney->Indiana
Posts: 182 whitelines User rank is Corporal (100 - 500 Reputation Level)whitelines User rank is Corporal (100 - 500 Reputation Level)whitelines User rank is Corporal (100 - 500 Reputation Level)whitelines User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 15 h 8 m 29 sec
Reputation Power: 9
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

Reply With Quote
  #4  
Old October 8th, 2003, 07:18 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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


Reply With Quote
  #5  
Old October 8th, 2003, 07:35 AM
whitelines's Avatar
whitelines whitelines is offline
action=(isSleep())?sleep:code;
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Sydney->Indiana
Posts: 182 whitelines User rank is Corporal (100 - 500 Reputation Level)whitelines User rank is Corporal (100 - 500 Reputation Level)whitelines User rank is Corporal (100 - 500 Reputation Level)whitelines User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 15 h 8 m 29 sec
Reputation Power: 9
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

Reply With Quote
  #6  
Old October 8th, 2003, 10:19 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
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.

Reply With Quote
  #7  
Old October 8th, 2003, 06:43 PM
whitelines's Avatar
whitelines whitelines is offline
action=(isSleep())?sleep:code;
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Sydney->Indiana
Posts: 182 whitelines User rank is Corporal (100 - 500 Reputation Level)whitelines User rank is Corporal (100 - 500 Reputation Level)whitelines User rank is Corporal (100 - 500 Reputation Level)whitelines User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 15 h 8 m 29 sec
Reputation Power: 9
Thanks Mark, I'll have a play and check it out.
Cheers,
Benjamin

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > finding who's online


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway