Latest Episode
 

Go Back   Keith and The Girl Forums Keith and The Girl Forums Talk Shite

Talk Shite General discussion

Reply
 
Thread Tools Display Modes
Old 05-05-2009, 08:30 PM   #241 (permalink)
Senior Member
 
dzagama's Avatar
 
Join Date: May 2007
Location: pacinian corpuscle.
Posts: 1,868
Quote:
Originally Posted by hayroob View Post
I might write a python script and set it up as a cron job. Might just do it in the push notification app. If there's an effective way to do it using something like pythons sets I would be into that.
Dammit. I see you guys talking about the server specs, but I can't find the link to the doc. Can you throw it up again?

I'm still not 100% on what the server does. Just logs identifiers and sends them to an Apple gateway for push notifications?
(Offline)   Reply With Quote
Old 05-05-2009, 08:33 PM   #242 (permalink)
Administrator
 
hayroob's Avatar
 
Join Date: Mar 2008
Location: Detroitish
Posts: 1,654
Quote:
Originally Posted by dzagama View Post
Dammit. I see you guys talking about the server specs, but I can't find the link to the doc. Can you throw it up again?

I'm still not 100% on what the server does. Just logs identifiers and sends them to an Apple gateway for push notifications?
I posted the relevant php like 45 minutes ago, I'm just compiling a feed of deviceTokens that I will use in a desktop app to send updates to phones.
(Offline)   Reply With Quote
Old 05-05-2009, 11:24 PM   #243 (permalink)
Member
 
Join Date: Mar 2006
Posts: 42
Are you trying to remove duplicates in the $dev variable or duplicate lines in the file? If it's duplicate lines in the file, this should do it:

Code:
$lines = file($filename);
if (!in_array($front.$deviceToken.$back,$lines))
{
    //append to file code in here
}
Also, you probably want to add a newline character "\n" to the end of each token when you write it to the file.

Last edited by s1lentslayer; 05-05-2009 at 11:26 PM.
(Offline)   Reply With Quote
Old 05-05-2009, 11:30 PM   #244 (permalink)
Administrator
 
hayroob's Avatar
 
Join Date: Mar 2008
Location: Detroitish
Posts: 1,654
Quote:
Originally Posted by s1lentslayer View Post
Are you trying to remove duplicates in the $dev variable or duplicate lines in the file? If it's duplicate lines in the file, this should do it:

Code:
$lines = file($filename);
if (!in_array($front.$deviceToken.$back,$lines))
{
    //append to file code in here
}
Also, you probably want to add a newline character "\n" to the end of each token when you write it to the file.
I'll give this a try, thanks.
(Offline)   Reply With Quote
Old 05-05-2009, 11:55 PM   #245 (permalink)
Administrator
 
hayroob's Avatar
 
Join Date: Mar 2008
Location: Detroitish
Posts: 1,654
Ok questions.

First, can you just stick /n in the middle of a string like

Code:
$back1 = '</device>\n';
because it seems to break things.

Second I'm trying to generate a feed that looks like this
Code:
<?xml version="1.0" encoding="utf-8"?>
<root>
<device><deviceToken>c32f8b7c e8d02a51 ce296c62 d3da4cb3 84fed78d b24545db fd949a73 132f2b50</deviceToken></device>
<device><deviceToken>c32f8b7c e8d02a51 ce296c62 d3da4cb3 84fed78d b24545db fd949a73 132f2b50</deviceToken></device>
</root>
right now the php code looks like this

Code:
<?php
	$deviceTokenUF = $_GET['dev'];
	$deviceToken = substr($deviceTokenUF, 1, -1);
	
	$filename = 'tokenLog';
	$front1 = '<device>';
	$front2 = '<deviceToken>';
	$back2 = '</deviceToken>';
	$back1 = '</device>';
	// Let's make sure the file exists and is writable first.
	if (is_writable($filename)) {
	    // In our example we're opening $filename in append mode.
	    // The file pointer is at the bottom of the file hence
	    // that's where $clientMessage will go when we fwrite() it.
	    if (!$handle = fopen($filename, 'a')) {
	         echo "Cannot open file ($filename)";
	         exit;
	    }
	    // Write $clientMessage to our opened file.
	    if (fwrite($handle, $front1.$front2.$deviceToken.$back2.$back1) === FALSE) {
	        echo "Cannot write to file ($filename)";
	        exit;
	    }
	    echo "Success, wrote ($clientMessage) to file ($filename)";
	    fclose($handle);
	} else {
	    echo "The file $filename is not writable";
	}
?>
I need to integrate in the duplicate checking and change it so that instead of inserting the line at the end of the file it sticks it in one up (above the </root>.

I'm a php dummy dumb, so any help would be useful. Also bear in mind that this might eventually become a hightraffic piece of code so tight and fast is important.
__________________
If you like the KATG app feel free to kick in some bucks (or don't)
KATGIPHONE Donation
(Offline)   Reply With Quote
Old 05-06-2009, 12:44 AM   #246 (permalink)
Administrator
 
hayroob's Avatar
 
Join Date: Mar 2008
Location: Detroitish
Posts: 1,654
Ok so here's where I am now, the line duplication doesn't seem to be detected.
Code:
<?php
	$deviceTokenUF = $_GET['dev'];
	$deviceToken = substr($deviceTokenUF, 1, -1);
	
	$filename = 'tokenLog';
	$front1 = '<device>';
	$front2 = '<deviceToken>';
	$back2 = '</deviceToken>';
	$back1 = '</device>';
	// Let's make sure the file exists and is writable first.
	if (is_writable($filename)) {
	    // In our example we're opening $filename in append mode.
	    // The file pointer is at the bottom of the file hence
	    // that's where $clientMessage will go when we fwrite() it.
	    if (!$handle = fopen($filename, 'r+')) {
	         echo "Cannot open file ($filename)";
	         exit;
	    }
		
		$lines = file($filename);
		$numElements = count($lines);
		for($i = 0; $i < $numElements - 1; $i++)
			{
				print $lines[$i];
				print '
				';
			}
		if (!in_array($front1.$front2.$deviceToken.$back2.$back1, $lines))
		{
			print 'Not In Array
			';
			for($i = 0; $i < $numElements - 1; $i++)
			{
				fwrite($handle, $lines[$i]);
			}
    		fwrite($handle, $front1.$front2.$deviceToken.$back2.$back1.'
    		');
    		fwrite($handle, $lines[$numElements - 1]);
		} else {
			print 'In Array
			';
			for($i = 0; $i < $numElements; $i++)
			{
				fwrite($handle, $lines[$i]);
			}
		}
	    
	    echo "Success, wrote ($clientMessage) to file ($filename)";
	    fclose($handle);
	} else {
	    echo "The file $filename is not writable";
	}
?>
Is there a decent PHP debugger so I can step through and see the variables I'm trying to work on. I've tried some debuggers in the past and always found them confusing.

Last edited by hayroob; 05-06-2009 at 01:09 AM.
(Offline)   Reply With Quote
Old 05-06-2009, 04:43 AM   #247 (permalink)
Senior Member
 
FrozenViking's Avatar
 
Join Date: May 2008
Location: Norway, its fuckin cold
Posts: 302
try dreamweaver, should work with php

if you dont have it, download it. its fuckin expensive
(Offline)   Reply With Quote
Old 05-06-2009, 08:27 AM   #248 (permalink)
Member
 
Join Date: Mar 2006
Posts: 42
First, create the file with no entries that starts like this:

Code:
<?xml version="1.0" encoding="utf-8"?>
<root>
</root>
Then try this:
Code:
<?php
    $deviceTokenUF = $_GET['dev'];
    $deviceToken = substr($deviceTokenUF, 1, -1);

    $filename = 'tokenLog';

    $line_to_add = "<device><devicetoken>$deviceToken</deviceToken></device>";
    
    //see if this line exists
    $lines = file($filename);
    if (!in_array($line_to_add,$lines))
    {
        //doesn't exist

        //first pop off last </root> element and add it back later
        array_pop($lines);
            
        //now add new device token line
        array_push($lines,$line_to_add);
            
        //now add </root> line
        array_push($lines,"</root>");
            
        //now combine into one string separated by newlines
         $new_lines = implode("\n",$lines);

        // Let's make sure the file exists and is writable first.
        if (is_writable($filename)) {
            if (!$handle = fopen($filename, 'w')) {
                 echo "Cannot open file ($filename)";
                 exit;
            }

            //lock the file for writing
            flock($fp, LOCK_EX);

            //write string to file
            fwrite($handle,$new_lines);

            // release the lock
            flock($fp, LOCK_UN);

            echo "Success, wrote ($clientMessage) to file ($filename)";
            fclose($handle);
        } else {
            echo "The file $filename is not writable";
        }
    }

?>

Last edited by s1lentslayer; 05-06-2009 at 08:33 AM.
(Offline)   Reply With Quote
Old 05-06-2009, 08:58 AM   #249 (permalink)
Senior Member
 
yoav's Avatar
 
Join Date: Apr 2006
Posts: 1,050
Quote:
Originally Posted by FrozenViking View Post
try dreamweaver, should work with php

if you dont have it, download it. its fuckin expensive
that or Textmate
(Offline)   Reply With Quote
Old 05-06-2009, 08:59 AM   #250 (permalink)
Senior Member
 
hypercrypt's Avatar
 
Join Date: Nov 2006
Location: My Place: Liverpool. Born and raised in Berlin.
Posts: 771
TextMate is THE best text editor ever!
(Offline)   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


All times are GMT -5. The time now is 08:51 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
Keith and The Girl