You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by ji...@wipro.com on 2014/11/13 10:28:25 UTC

basic twitter stream program not working.

Hi
       I am trying to run a basic twitter stream program but getting blank output. Please correct me if I am missing something.

import org.apache.spark.SparkConf
import org.apache.spark.streaming.StreamingContext
import org.apache.spark.streaming.twitter.TwitterUtils
import org.apache.spark.streaming.Seconds
import org.apache.log4j.LogManager
import org.apache.log4j.Level

object Sparktwiter1 {
  def main(args: Array[String]) {
LogManager.getRootLogger().setLevel(Level.ERROR);
    System.setProperty("http.proxyHost", "proxy4.wipro.com");
    System.setProperty("http.proxyPort", "8080");
    System.setProperty("twitter4j.oauth.consumerKey", "")
    System.setProperty("twitter4j.oauth.consumerSecret", "")
    System.setProperty("twitter4j.oauth.accessToken", "")
    System.setProperty("twitter4j.oauth.accessTokenSecret", "")
    val sparkConf = new SparkConf().setAppName("TwitterPopularTags").setMaster("local").set("spark.eventLog.enabled", "true")
    val ssc = new StreamingContext(sparkConf, Seconds(2))
    val stream = TwitterUtils.createStream(ssc, None)//, filters)
    stream.print
    val s1 = stream.flatMap(status => status.getText)
    s1.print
    val hashTags = stream.flatMap(status => status.getText.split(" ").filter(_.startsWith("#")))
    hashTags.print
     ssc.start()
    ssc.awaitTermination()
  }
}

Output

-------------------------------------------
Time: 1415869348000 ms
-------------------------------------------

-------------------------------------------
Time: 1415869348000 ms
-------------------------------------------

-------------------------------------------
Time: 1415869348000 ms
-------------------------------------------

[cid:image005.jpg@01CFFF52.453A17F0]


[cid:image006.jpg@01CFFF52.453A17F0]


The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

www.wipro.com

RE: basic twitter stream program not working.

Posted by ji...@wipro.com.
Hi
            Thanks Akhil  you saved the day….      Its working perfectly …

Regards
Jishnu Menath Prathap
From: Akhil Das [mailto:akhil@sigmoidanalytics.com]
Sent: Thursday, November 13, 2014 3:25 PM
To: Jishnu Menath Prathap (WT01 - BAS)
Cc: Akhil [via Apache Spark User List]; user@spark.apache.org
Subject: Re: basic twitter stream program not working.

Change this line

val sparkConf = new SparkConf().setAppName("TwitterPopularTags").setMaster("local").set("spark.eventLog.enabled","true")

to

val sparkConf = new SparkConf().setAppName("TwitterPopularTags").setMaster("local[4]").set("spark.eventLog.enabled","true")



Thanks
Best Regards

On Thu, Nov 13, 2014 at 2:58 PM, <ji...@wipro.com>> wrote:
Hi
       I am trying to run a basic twitter stream program but getting blank output. Please correct me if I am missing something.

import org.apache.spark.SparkConf
import org.apache.spark.streaming.StreamingContext
import org.apache.spark.streaming.twitter.TwitterUtils
import org.apache.spark.streaming.Seconds
import org.apache.log4j.LogManager
import org.apache.log4j.Level

object Sparktwiter1 {
  def main(args: Array[String]) {
LogManager.getRootLogger().setLevel(Level.ERROR);
    System.setProperty("http.proxyHost", "proxy4.wipro.com<http://proxy4.wipro.com>");
    System.setProperty("http.proxyPort", "8080");
    System.setProperty("twitter4j.oauth.consumerKey", "")
    System.setProperty("twitter4j.oauth.consumerSecret", "")
    System.setProperty("twitter4j.oauth.accessToken", "")
    System.setProperty("twitter4j.oauth.accessTokenSecret", "")
    val sparkConf = new SparkConf().setAppName("TwitterPopularTags").setMaster("local").set("spark.eventLog.enabled", "true")
    val ssc = new StreamingContext(sparkConf, Seconds(2))
    val stream = TwitterUtils.createStream(ssc, None)//, filters)
    stream.print
    val s1 = stream.flatMap(status => status.getText)
    s1.print
    val hashTags = stream.flatMap(status => status.getText.split(" ").filter(_.startsWith("#")))
    hashTags.print
     ssc.start()
    ssc.awaitTermination()
  }
}

Output

-------------------------------------------
Time: 1415869348000 ms
-------------------------------------------

-------------------------------------------
Time: 1415869348000 ms
-------------------------------------------

-------------------------------------------
Time: 1415869348000 ms
-------------------------------------------

[cid:image001.jpg@01CFFF64.0FD789F0]


[cid:image002.jpg@01CFFF64.0FD789F0]


The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments.

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

www.wipro.com<http://www.wipro.com>


The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.

www.wipro.com

Re: basic twitter stream program not working.

Posted by Akhil Das <ak...@sigmoidanalytics.com>.
Change this line

*val* sparkConf = *new* SparkConf().setAppName("TwitterPopularTags"
).setMaster("local").set("spark.eventLog.enabled","true")

to

*val* sparkConf = *new* SparkConf().setAppName("TwitterPopularTags"
).setMaster(*"local[4]"*).set("spark.eventLog.enabled","true")



Thanks
Best Regards

On Thu, Nov 13, 2014 at 2:58 PM, <ji...@wipro.com> wrote:

>   *Hi *
>
> *       I am trying to run a basic twitter stream program but getting
> blank output. Please correct me if I am missing something.*
>
>
>
> *import* org.apache.spark.SparkConf
>
> *import* org.apache.spark.streaming.StreamingContext
>
> *import* org.apache.spark.streaming.twitter.TwitterUtils
>
> *import* org.apache.spark.streaming.Seconds
>
> *import* org.apache.log4j.LogManager
>
> *import* org.apache.log4j.Level
>
>
>
> *object* Sparktwiter1 {
>
>   *def* main(args: Array[String]) {
>
> LogManager.getRootLogger().setLevel(Level.ERROR);
>
>     System.setProperty("http.proxyHost", "proxy4.wipro.com");
>
>     System.setProperty("http.proxyPort", "8080");
>
>     System.setProperty("twitter4j.oauth.consumerKey", "")
>
>     System.setProperty("twitter4j.oauth.consumerSecret", "")
>
>     System.setProperty("twitter4j.oauth.accessToken", "")
>
>     System.setProperty("twitter4j.oauth.accessTokenSecret", "")
>
>     *val* sparkConf = *new* SparkConf().setAppName("TwitterPopularTags"
> ).setMaster("local").set("spark.eventLog.enabled", "true")
>
>     *val* ssc = *new* StreamingContext(sparkConf, Seconds(2))
>
>     *val* stream = TwitterUtils.createStream(ssc, None)//, filters)
>
>     stream.print
>
>     *val* s1 = stream.flatMap(status => *status.getText*)
>
>     s1.print
>
>     *val* hashTags = stream.flatMap(status => *status.getText.split(**" "*
> *).filter(_.startsWith(**"#"**))*)
>
>     hashTags.print
>
>      ssc.start()
>
>     ssc.awaitTermination()
>
>   }
>
> }
>
>
>
> Output
>
>
>
> -------------------------------------------
>
> Time: 1415869348000 ms
>
> -------------------------------------------
>
>
>
> -------------------------------------------
>
> Time: 1415869348000 ms
>
> -------------------------------------------
>
>
>
> -------------------------------------------
>
> Time: 1415869348000 ms
>
> -------------------------------------------
>
>
>
>
>
>
>
>
>
> The information contained in this electronic message and any attachments
> to this message are intended for the exclusive use of the addressee(s) and
> may contain proprietary, confidential or privileged information. If you are
> not the intended recipient, you should not disseminate, distribute or copy
> this e-mail. Please notify the sender immediately and destroy all copies of
> this message and any attachments.
>
> WARNING: Computer viruses can be transmitted via email. The recipient
> should check this email and any attachments for the presence of viruses.
> The company accepts no liability for any damage caused by any virus
> transmitted by this email.
>
> www.wipro.com
>