<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SMM Guru - The Social Media Marketing Guru &#187; scripts</title>
	<atom:link href="http://www.smmguru.com/tag/scripts/feed" rel="self" type="application/rss+xml" />
	<link>http://www.smmguru.com</link>
	<description></description>
	<lastBuildDate>Tue, 06 Apr 2010 18:56:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Expanding On TwitterBot &#8211; Keep Track of Used Tweets</title>
		<link>http://www.smmguru.com/2008/11/03/expanding-on-twitterbot-keep-track-of-used-tweets</link>
		<comments>http://www.smmguru.com/2008/11/03/expanding-on-twitterbot-keep-track-of-used-tweets#comments</comments>
		<pubDate>Mon, 03 Nov 2008 18:30:48 +0000</pubDate>
		<dc:creator>Tyler</dc:creator>
				<category><![CDATA[Resources]]></category>
		<category><![CDATA[Social Media]]></category>
		<category><![CDATA[Social Media Marketing]]></category>
		<category><![CDATA[TwitterBot]]></category>
		<category><![CDATA[bots]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://www.smmguru.com/?p=467</guid>
		<description><![CDATA[Now that you know how to make a Twitter bot you may be looking to add some more functionality to it. One problem you may run into after some time is that you keep recycling or re-sending the same messages to Twitter. For example, you have 100 facts about your self and you don&#8217;t want [...]]]></description>
			<content:encoded><![CDATA[<p>Now that you know <a href="http://www.smmguru.com/2008/10/31/how-to-make-a-twitter-bot-with-php-in-five-minuets" target="_blank">how to make a Twitter bot</a> you may be looking to add some more functionality to it. One problem you may run into after some time is that you keep recycling or re-sending the same messages to Twitter. For example, you have 100 facts about your self and you don&#8217;t want any of them to appear twice but you want everything to be automated. How do you do this? Easy, just add a status field to your `tweets` table.</p>
<p><strong>Step 1 &#8211; Add the field.</strong><br />
To add the field you can use the simple graphical interface in phpMyAdmin or use the SQL tab (or alternative) to run this code:</p>
<p>ALTER TABLE `tweets` ADD `status` VARCHAR(10) NOT NULL;</p>
<p>What this will do is create a new field in your tweets table with 10 characters of space for that messages status. We will be setting them all to &#8220;ready&#8221;, and later changing our PHP code to update them as we go along.</p>
<p><strong>Step 2 &#8211; Set all tweets to ready.</strong><br />
After you have the new field added to your database you will need to set all of the tweets you want to use to &#8216;ready&#8217; status. In this example, only tweets with the status set to &#8216;ready&#8217; can be randomly selected.</p>
<p>While inside of phpMyAdmin (SQL tab) or what ever tool you use, go to the page that allows you to run MySQL commands on your tables and enter this code:</p>
<p>UPDATE `tweets` SET `status` = &#8216;ready&#8217;</p>
<p>Alternatively you can pick which ones you want to use if you already have some tweets that you wish not to recycle. This SQL command will update every tweet/message you have in your database so use it wisely.</p>
<p><strong>Step 3 &#8211; Modify PHP to update tweet status in database.</strong><br />
Our third an final step is to modify the php script so it will change the status of every used tweet. To do this, we will make a few simple changes to our original code.</p>
<p>First off, we have to change the MySQL query so it will only pull random messages with &#8220;ready&#8221; status:</p>
<div class="php php" style="font-family:monospace;color: #006; padding:8px; background-color: #f0f0f0;"><span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <a style="color: #000060;" href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a> <span style="color: #009900;">(</span>“SELECT <span style="color: #339933;">*</span> FROM tweets WHERE status <span style="color: #339933;">=</span> <span>&#8216;ready&#8217;</span> ORDER BY <a style="color: #000060;" href="http://www.php.net/rand"><span style="color: #990000;">RAND</span></a><span style="color: #009900;">(</span><span style="color: #009900;">)</span> LIMIT <span style="color: #cc66cc;">1</span><span style="font-style: italic; color: #666666;">);</span></div>
<p>For our second change, we will need to get the ID number of the tweet from the database and pass it to the sendTweet() function we will modify in a moment:</p>
<div class="php php" style="font-family:monospace;color: #006; padding:8px; background-color: #f0f0f0;"><span style="color: #b1b100;">while</span><span style="color: #009900;">(</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <a style="color: #000060;" href="http://www.php.net/mysql_fetch_array"><span style="color: #990000;">mysql_fetch_array</span></a><span style="color: #009900;">(</span><span style="color: #000088;">$result</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span><span style="color: #009900;">{</span></p>
<p><span style="color: #000088;">$tweet</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&#8220;$row[tweet]&#8220;</span>;</p>
<p><span style="color: #000088;">$tweetID</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&#8220;$row[id]&#8220;</span>;</p>
<p>sendTweet<span style="color: #009900;">(</span><span style="color: #000088;">$tweet</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tweetID</span><span style="color: #009900;">)</span>;</p>
<p><span style="color: #009900;">}</span></div>
<p>Then we modify our sendTweet() function to handle the tweet&#8217;s ID, and then change its status if the message is successfully sent to Twitter:</p>
<div class="php php" style="font-family:monospace;color: #006;padding:8px; background-color: #f0f0f0;"><span style="font-weight: bold; color: #000000;">function</span> sendTweet<span style="color: #009900;">(</span><span style="color: #000088;">$msg</span><span style="color: #339933;">,</span> <span style="color: #000088;">$idoftweet</span><span style="color: #009900;">)</span><span style="color: #009900;">{</span></p>
<p><span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> ‘TWITTER<span style="color: #339933;">-</span>USER<span style="color: #339933;">-</span>NAME’;</p>
<p><span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> ‘TWITTER<span style="color: #339933;">-</span>PASS’;</p>
<p><span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> ‘http<span style="color: #339933;">:</span><span style="font-style: italic; color: #666666;">//twitter.com/statuses/update.xml’;</span></p>
<p><span style="color: #000088;">$curl_handle</span> <span style="color: #339933;">=</span> curl_init<span style="color: #009900;">(</span><span style="color: #009900;">)</span>;</p>
<p>curl_setopt<span style="color: #009900;">(</span><span style="color: #000088;">$curl_handle</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> “<span style="color: #000088;">$url</span>”<span style="color: #009900;">)</span>;</p>
<p>curl_setopt<span style="color: #009900;">(</span><span style="color: #000088;">$curl_handle</span><span style="color: #339933;">,</span> CURLOPT_CONNECTTIMEOUT<span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">)</span>;</p>
<p>curl_setopt<span style="color: #009900;">(</span><span style="color: #000088;">$curl_handle</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">)</span>;</p>
<p>curl_setopt<span style="color: #009900;">(</span><span style="color: #000088;">$curl_handle</span><span style="color: #339933;">,</span> CURLOPT_POST<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">)</span>;</p>
<p>curl_setopt<span style="color: #009900;">(</span><span style="color: #000088;">$curl_handle</span><span style="color: #339933;">,</span> CURLOPT_POSTFIELDS<span style="color: #339933;">,</span> “status<span style="color: #339933;">=</span><span style="color: #000088;">$msg</span>”<span style="color: #009900;">)</span>;</p>
<p>curl_setopt<span style="color: #009900;">(</span><span style="color: #000088;">$curl_handle</span><span style="color: #339933;">,</span> CURLOPT_USERPWD<span style="color: #339933;">,</span> “<span style="color: #000088;">$username</span><span style="color: #339933;">:</span><span style="color: #000088;">$password</span>”<span style="color: #009900;">)</span>;</p>
<p><span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> curl_exec<span style="color: #009900;">(</span><span style="color: #000088;">$curl_handle</span><span style="color: #009900;">)</span>;</p>
<p>curl_close<span style="color: #009900;">(</span><span style="color: #000088;">$curl_handle</span><span style="color: #009900;">)</span>;</p>
<p><span style="color: #b1b100;">if</span> <span style="color: #009900;">(</span><a style="color: #000060;" href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">(</span><span style="color: #000088;">$buffer</span><span style="color: #009900;">)</span><span style="color: #009900;">)</span> <span style="color: #009900;">{</span></p>
<p><a style="color: #000060;" href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> ‘fail’;</p>
<p><span style="color: #009900;">}</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">{</span></p>
<p><a style="color: #000060;" href="http://www.php.net/echo"><span style="color: #990000;">echo</span></a> ’success’;</p>
<p><a style="color: #000060;" href="http://www.php.net/mysql_query"><span style="color: #990000;">mysql_query</span></a><span style="color: #009900;">(</span><span style="color: #0000ff;">&#8220;UPDATE `tweets` SET `status` = &#8216;used&#8217; WHERE id = &#8216;$idoftweet&#8217;&#8221;</span><span style="color: #009900;">)</span>;</p>
<p><span style="color: #009900;">}</span></div>
<p>Now it&#8217;s all ready to role. Now every time a message is pulled from the database and sent to Twitter (successfully) it will have it&#8217;s status changed to &#8220;used&#8221; taking it out of the possible messages to send. Just upload your new php file, re-activate your CRON job and have some fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.smmguru.com/2008/11/03/expanding-on-twitterbot-keep-track-of-used-tweets/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
