Showing Internet download usage

Discussion in 'Pascal Logic Code Examples' started by Garfield, Apr 16, 2009.

  1. Garfield

    Garfield

    Joined:
    Dec 3, 2004
    Messages:
    24
    Likes Received:
    0
    Location:
    Adelaide
    I have used the new E-Mail facilities in Colour C-Touch to display how much of our download allocation has been used. It works for Adam Internet, but changes may be required for other ISPs. Adam Internet can send an e-mail each day once you have used 50% of your monthly quota. The logic below reads this e-mail and displays the usage on a slider.

    The steps are:
    A. Get a separate e-mail account for your Colour C-Touch (this is important because it deletes all e-mails once they are read)
    B. Put the e-mail account details in PICED
    C. Add a system io variable called Download Usage
    D. Add a slider to show the Download Usage value
    E. Add the logic code below

    Code:
    { constants }
    EMailAccountNumber = 2;
    
    { variables }
    EMailCount : integer;
    EMailNumber : integer;
    EMailSender : string;
    EMailSubject : string;
    PercentPos : integer;
    PercentString : string;
    
    { module }
    
    { look for an e-mail containing the download usage from the ISP }
    EMailCount := GetEMailCount(EMailAccountNumber);
    for EMailNumber := 0 to EMailCount - 1 do
    begin
      GetEMailSender(EMailAccountNumber, 0, EMailSender);
      LogMessage('E-Mail from ', EMailSender);
      if pos('[email protected]', EMailSender) > 0 then
      begin
        GetEMailSubject(EMailAccountNumber, 0, EMailSubject);
        LowerCase(EMailSubject);
        PercentPos := pos('%', EMailSubject);
        if PercentPos > 0 then
        begin
          copy(PercentString, EMailSubject, PercentPos - 5, 2);
          SetIntSystemIO("Download Usage", StringToInt(PercentString));
          LogMessage('Download Usage = ',PercentString, '%');
        end
        else
        begin
          PercentPos := pos('over quota', EMailSubject);
          if PercentPos > 0 then
          begin
            SetIntSystemIO("Download Usage", 100);
            LogMessage('Download Usage = 100%');
          end;
        end;
      end;
      DeleteEMail(EMailAccountNumber, 0);
      LogMessage('Delete E-Mail');
    end;
    { reset at the start of the 28th day of the month }
    once day = 28 then
      SetIntSystemIO("Download Usage", 0);
    delay(600);
    
    Edited 23/8/09 due to change in the e-mail message format from Adam Internet.
     
    Last edited by a moderator: Aug 23, 2009
    Garfield, Apr 16, 2009
    #1
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.