Skip to content

Instantly share code, notes, and snippets.

@Corinrypkema
Last active December 27, 2015 10:49
Show Gist options
  • Save Corinrypkema/7314010 to your computer and use it in GitHub Desktop.
Save Corinrypkema/7314010 to your computer and use it in GitHub Desktop.
Doorbell
/* system example : DIR */
#include <stdio.h> /* printf */
#include <stdlib.h> /* system, NULL, EXIT_FAILURE */
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <windows.h>
using namespace std;
int main ()
{
/***************** Fetch init ***************/
int i;
printf ("Checking if processor is available...");
if (system(NULL)) puts ("Ok");
else exit (EXIT_FAILURE);
printf ("Connecting to server... \n");
i=system ("curl http://corin.rypkema.org/counter.php?page=holder > file.doorbell");
//printf ("\nThe value returned was: %d.\n",i);
// printf("%d\n", i);
int initcount = 0;
string line;
ifstream myfile ("file.doorbell");
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
stringstream(line.substr(line.find_first_of("\'")+1,(line.find_last_of("\'")-line.find_first_of("\'"))-1)) >> initcount;
//cout << initcount<<endl;
}
myfile.close();
}
else cout << "Unable to open file";
cout << "Connected.\n";
i=system ("pause");
/***************** loop ***************/
int reloadcnt = 0;
for(;;){
reloadcnt++;
Sleep(1000);//go easy on the network lol
int d;
d=system ("cls");
printf ("Checking if processor is available... ");
if (system(NULL)) puts ("Ok");
else exit (EXIT_FAILURE);
printf ("Downloading...\n\n");
d=system ("curl http://corin.rypkema.org/counter.php?page=holder > file.doorbell");
int newcount = 0;
string lined;
ifstream myfiled ("file.doorbell");
if (myfiled.is_open())
{
while ( getline (myfiled,lined) )
{
stringstream(lined.substr(lined.find_first_of("\'")+1,(lined.find_last_of("\'")-lined.find_first_of("\'"))-1)) >> newcount;
if(newcount-reloadcnt>initcount){
printf("DINGDANG\n");
PlaySound("E:\\eclipse\\doorbell.wav", NULL, SND_ASYNC);
initcount = newcount-reloadcnt;
}
}
myfile.close();
}
else cout << "Unable to open file";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment