Difference between revisions of "MM-Tweeter"

From MidsouthMakers - Memphis Area Hackerpace
Jump to navigation Jump to search
 
(12 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
* Running via CLI PHP
 
* Running via CLI PHP
 
* Design an application to use Matt Harris' library as a function to auto tweet events based on existing conditions
 
* Design an application to use Matt Harris' library as a function to auto tweet events based on existing conditions
 +
 +
==Project Status==
 +
* Functional
 +
 +
==Software License==
 +
* TBD - Source Currently Unavailable
 +
 +
==Usage==
 +
* Build a HTTP request with the following variables
 +
** source (Your Source - predetermined)
 +
** secret (Your secret - predetermined)
 +
** post_date (When the tweet should be posted + 5 minutes)
 +
** content (this is what you want tweeted)
 +
* Example: <pre>http://api.midsouthmakers.org/mm-tweeter/?source=samplesource&secret=samplesecret&post_date=2012-05-07%2011:46:10&content=Sample Tweet</pre>
 +
** $_POST or $_GET methods should work in the same manner.
 +
* Execute the request
 +
* Currently debugging information is turned on.
 +
* Please report any errors.
  
 
==Current Functionality==
 
==Current Functionality==
Line 9: Line 27:
 
* Able to be run from a url to post static tweets.
 
* Able to be run from a url to post static tweets.
 
* Checks pending table and checks if their post date < current time
 
* Checks pending table and checks if their post date < current time
 +
* Cron running every 30 minutes to post any pending
 +
* If there is an error with a tweet it will try to tweet it $attempts times (Default 3)
 +
** If it is unable to be tweeted (Error Code != 200) after $attempts times it is deleted from pending and added to history with the last error code
  
 
==To Be Done==
 
==To Be Done==
* Need to handle adding to pending table
+
* Perhaps ability for source to query their tweets based on history/pending?
* Need to handle adding to history
+
* <del>Need to ensure response code making it back to user</del> Solved By: Impossible since we're always tweeting into the future. Refer to ability of source to query their history
* Need to handle Remove from pending
+
* <del>Need to handle adding to pending table</del>
* Cron local system to test for pending tweets
+
* <del>Need to handle adding to history</del>
 +
* <del>Need to handle Remove from pending</del>
 +
* <del>Cron local system to test for pending tweets</del>
 +
* <del>Need to provide fallback if no $post_date supplied.</del>
 +
* <del>Need to add warning if $content > 160 characters OR Blank.</del> Solved by: they're using a twitter api, they should self limit <= 160 characters
 +
* <del>Need ensure $content is not NULL in addpending()</del> Solved by: checking if $content = '' before addpending()
 +
* <del>Log post attempts? Check error codes so we're not hammering away at twitter</del> Solved by: $attempts checking: default 3
  
 
==Goals==
 
==Goals==
Line 30: Line 57:
 
   `added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 
   `added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
 
   `source` varchar(255) NOT NULL,
 
   `source` varchar(255) NOT NULL,
 +
  `attempts` int(1) NOT NULL,
 +
  `last_error_code` int(3) NOT NULL,
 
   PRIMARY KEY (`id`)
 
   PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1;
+
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;
 
</pre>
 
</pre>
 
* History Table
 
* History Table

Latest revision as of 22:28, 9 June 2012

Conditional Auto Tweeter written in PHP

  • Using OAuth Library by Matt Harris: https://github.com/themattharris/tmhOAuth
  • Running via CLI PHP
  • Design an application to use Matt Harris' library as a function to auto tweet events based on existing conditions

Project Status

  • Functional

Software License

  • TBD - Source Currently Unavailable

Usage

  • Build a HTTP request with the following variables
    • source (Your Source - predetermined)
    • secret (Your secret - predetermined)
    • post_date (When the tweet should be posted + 5 minutes)
    • content (this is what you want tweeted)
  • Example:
    http://api.midsouthmakers.org/mm-tweeter/?source=samplesource&secret=samplesecret&post_date=2012-05-07%2011:46:10&content=Sample Tweet
    • $_POST or $_GET methods should work in the same manner.
  • Execute the request
  • Currently debugging information is turned on.
  • Please report any errors.

Current Functionality

  • Using MidsouthMakersDev Twitter account
  • Able to be run from the command line to post static tweets.
  • Able to be run from a url to post static tweets.
  • Checks pending table and checks if their post date < current time
  • Cron running every 30 minutes to post any pending
  • If there is an error with a tweet it will try to tweet it $attempts times (Default 3)
    • If it is unable to be tweeted (Error Code != 200) after $attempts times it is deleted from pending and added to history with the last error code

To Be Done

  • Perhaps ability for source to query their tweets based on history/pending?
  • Need to ensure response code making it back to user Solved By: Impossible since we're always tweeting into the future. Refer to ability of source to query their history
  • Need to handle adding to pending table
  • Need to handle adding to history
  • Need to handle Remove from pending
  • Cron local system to test for pending tweets
  • Need to provide fallback if no $post_date supplied.
  • Need to add warning if $content > 160 characters OR Blank. Solved by: they're using a twitter api, they should self limit <= 160 characters
  • Need ensure $content is not NULL in addpending() Solved by: checking if $content = before addpending()
  • Log post attempts? Check error codes so we're not hammering away at twitter Solved by: $attempts checking: default 3

Goals

  • Take input from multiple sources
  • Reliably validate source of all incoming data
  • Use access list or secret hash to prevent abuse

Database Schema

  • Pending Table
CREATE TABLE IF NOT EXISTS `pending` (
  `id` int(6) NOT NULL AUTO_INCREMENT,
  `content` varchar(160) NOT NULL,
  `post_date` datetime NOT NULL,
  `added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `source` varchar(255) NOT NULL,
  `attempts` int(1) NOT NULL,
  `last_error_code` int(3) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;
  • History Table
CREATE TABLE IF NOT EXISTS `history` (
  `id` int(6) NOT NULL AUTO_INCREMENT,
  `content` varchar(160) NOT NULL,
  `post_date` date NOT NULL,
  `added` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `source` varchar(255) NOT NULL,
  `response_code` int(4) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;
  • Secrets Table
CREATE TABLE IF NOT EXISTS `secrets` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `source` varchar(255) NOT NULL,
  `secret` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 ;