public JsonResult GetStats() { // TweetStatModel TweetStats = new TweetStatModel(); TweetStatModel TweetStats = TwitterConfig.GetTweetStats(); return(Json(TweetStats, JsonRequestBehavior.AllowGet)); }
public async Task OnLoad(object data) { if (!HasContexts) { var csa = new ConfirmServiceArgs(Strings.DoYouWantToAddANewAccount, Strings.NoAccountAdded); if (await ViewServiceRepository.Confirm(csa)) { await ViewServiceRepository.ShowAccounts(true); } } Task.Run(async() => { await CheckCredentials(); await ReportAppVersion(); }).Forget(); await Task.WhenAll(Columns.Select(c => c.Load(AsyncLoadContext.Ui))); // It's late and I didn't have enough coffee... ColumnsLocked = !Configuration.General.ColumnsLocked; await Dispatcher.RunAsync(ExecuteToggleColumnsLockCommand); try { await TwitterConfig.QueryConfig(); } catch (Exception ex) { LogTo.WarnException("Failed to read current config from twitter", ex); } await Task.WhenAll(CheckForUpdates(), QueryRateLimit()); }
static void Main(string[] args) { var twitterObserver = new TwitterObserver(); var twitterConfig = new TwitterConfig(Constants.TwitterConsumerKey, Constants.TwitterConsumerSecret, Constants.TwitterAccessToken, Constants.TwitterTokenSecret); Services.StreamStatuses(twitterConfig, "Microsoft").ToObservable().Subscribe(twitterObserver); }
static void Main(string[] args) { Console.WriteLine("================STARTING WHAT-THE-REPO================"); Global.counter = 0; getTweet(); TwitterConfig twitterConfig = new TwitterConfig(); // Allow Tweetinvi to throw exceptions ExceptionHandler.SwallowWebExceptions = false; // Twitter credentials Auth.SetUserCredentials(twitterConfig.CONSUMER_KEY, twitterConfig.CONSUMER_SECRET, twitterConfig.ACCESS_TOKEN, twitterConfig.ACCESS_TOKEN_SECRET); try { DateTime now = DateTime.Now; // Publish the Tweet var tweet = Tweet.PublishTweet(Global.tweetBody); Console.WriteLine("{0} ...... @whattherepo tweeted : {1}", now.ToString("F"), tweet); } catch (TwitterException ex) { // Twitter API Request has been failed; Bad request, network failure or unauthorized request Console.WriteLine("Something went wrong when we tried to execute the http request : '{0}'", ex.TwitterDescription); } Console.WriteLine("-------------------------------------------------------------------"); //Console.ReadLine(); }
public IEnumerable <Tweet> StreamStatuses(TwitterConfig config) { var jsonSerializer = new DataContractJsonSerializer(typeof(Tweet)); var streamReader = ReadTweets(config); while (!_cancellationToken.IsCancellationRequested) { string line = null; try { line = streamReader.ReadLine(); } catch (Exception e) { if (_logger.IsEnabled(LogLevel.Error)) { Console.WriteLine(e.Message); } } if (!string.IsNullOrWhiteSpace(line) && !line.StartsWith("{\"delete\"")) { var result = (Tweet)jsonSerializer.ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(line))); result.RawJson = line; yield return(result); } // Oops the Twitter has ended... or more likely some error have occurred. // Reconnect to the twitter feed. if (line == null) { streamReader = ReadTweets(config); } } }
public long CreateTweet(string text, TwitterConfig configuration) { SetAuth(configuration); var tweet = Tweet.PublishTweet(text); CheckExceptions(); return(tweet.Id); }
public bool DeleteTweet(long tweetId, TwitterConfig configuration) { SetAuth(configuration); var result = Tweet.DestroyTweet(tweetId); CheckExceptions("Невозможно удалить старый твит"); return(result); }
public TwitterFeedController(ITwitterService twitterService, IAuthorizationManager <MvcAuthorizer> authorizationManager, IOptions <TwitterConfig> twitterConfig) { _authorizationManager = authorizationManager; _twitterService = twitterService; _twitterConfig = twitterConfig.Value; }
public ActionResult GetNewTweets() { var twitterObserver = new TwitterObserver(); var twitterConfig = new TwitterConfig(Constants.TWITTER_CONSUMER_KEY, Constants.TWITTER_CONSUMER_SECRET, Constants.TWITTER_ACCESS_TOKEN, Constants.TWITTER_TOKEN_SECRET); Services.StreamStatuses(twitterConfig, "Microsoft").ToObservable().Subscribe(twitterObserver); return(RedirectToAction("ListTweets")); }
public void SetUp() { logger = new NullLogger <TrackingConfigFactory>(); config = new TwitterConfig(); tracking = new Mock <ITrackingManager>(); var tracker = new Mock <ITracker>(); tracking.Setup(item => item.Resolve(It.IsAny <string>(), It.IsAny <string>())).Returns(tracker.Object); instance = CreateFactory(); }
public void TestTwitter() { var streamInsightInstanceName = Properties.Settings.Default.InstanceName; var server = Server.Create(streamInsightInstanceName); var application = server.CreateApplication("twittertest"); var inputConfig = new TwitterConfig { Username = UserNameTbx.Text, Password = PasswordTbx.Text }; if (FilterModeRbn.Checked) { inputConfig.Mode = TwitterMode.Filter; inputConfig.Parameters = "track=" + FilterParametersTbx.Text; } else if (SampleModeRbn.Checked) { inputConfig.Mode = TwitterMode.Sample; } var input = CepStream <Tweet> .Create("twitter", typeof(TwitterFactory), inputConfig, EventShape.Point); // Configure output adapter var outputConfig = new StackerConfig { StackerCtlPipeName = stackerCtl1.PipeName, StackerCtlHostName = "localhost" }; // Create query and bind to the output adapter query = input.ToQuery(application, "query", "...", typeof(StackerFactory), outputConfig, EventShape.Point, StreamEventOrder.ChainOrdered); // Start query query.Start(); // Wait until query change state DiagnosticView diagnosticView; stopFlag = false; do { Thread.Sleep(100); diagnosticView = query.Application.Server.GetDiagnosticView(query.Name); } while (!stopFlag && (string)diagnosticView["QueryState"] == "Running"); // Stop query query.Stop(); application.Delete(); server.Dispose(); }
public void TestTwitter() { var streamInsightInstanceName = Properties.Settings.Default.InstanceName; var server = Server.Create(streamInsightInstanceName); var application = server.CreateApplication("twittertest"); var inputConfig = new TwitterConfig { Username = UserNameTbx.Text, Password = PasswordTbx.Text }; if (FilterModeRbn.Checked) { inputConfig.Mode = TwitterMode.Filter; inputConfig.Parameters = "track=" + FilterParametersTbx.Text; } else if (SampleModeRbn.Checked) inputConfig.Mode = TwitterMode.Sample; var input = CepStream<Tweet>.Create("twitter", typeof(TwitterFactory), inputConfig, EventShape.Point); // Configure output adapter var outputConfig = new StackerConfig { StackerCtlPipeName = stackerCtl1.PipeName, StackerCtlHostName = "localhost" }; // Create query and bind to the output adapter query = input.ToQuery(application, "query", "...", typeof(StackerFactory), outputConfig, EventShape.Point, StreamEventOrder.ChainOrdered); // Start query query.Start(); // Wait until query change state DiagnosticView diagnosticView; stopFlag = false; do { Thread.Sleep(100); diagnosticView = query.Application.Server.GetDiagnosticView(query.Name); } while (!stopFlag && (string)diagnosticView["QueryState"] == "Running"); // Stop query query.Stop(); application.Delete(); server.Dispose(); }
public static IProviderConfig GetImplementation(OAuthProviders provider) { IProviderConfig result = null; switch (provider) { case OAuthProviders.LinkedIn: result = new LinkedInConfig(); break; case OAuthProviders.Twitter: result = new TwitterConfig(); break; } return result; }
public void SetUp() { mockSentimentAnalysis = new Mock <ISentimentAnalysis>(); persistency = new Mock <ITwitPersistency>(); manager = new Mock <ITrackingManager>(); var tracker = new Mock <ITracker>(); manager.Setup(item => item.Resolve(It.IsAny <string>(), It.IsAny <string>())).Returns(tracker.Object); var config = new TwitterConfig(); config.Keywords = new[] { "Test" }; config.HashKeywords = true; config.Persistency = "Test"; trackingConfigFactory = new TrackingConfigFactory( new NullLogger <TrackingConfigFactory>(), config, manager.Object); instance = CreateInstance(); }
private void Authenticate() { TwitterConfig.InitApp(); // Initializing credentials -> Auth.SetUserCredentials if (Auth.Credentials == null || string.IsNullOrEmpty(Auth.Credentials.ConsumerKey) || string.IsNullOrEmpty(Auth.Credentials.ConsumerSecret) || string.IsNullOrEmpty(Auth.Credentials.AccessToken) || string.IsNullOrEmpty(Auth.Credentials.AccessTokenSecret) || Auth.Credentials.AccessToken == "ACCESS_TOKEN") { Message = "Please enter your credentials in the StreamViewModel.cs file"; } else { var user = User.GetAuthenticatedUser(); Message = string.Format("Hi '{0}'. Welcome on board with Windows 10 Universal App!", user.Name); } }
static void Main(string[] args) { Console.WriteLine("--------Iniciando Stream do Twitter--------------"); Console.WriteLine("................................................."); Console.WriteLine(""); IConfiguration config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", true, true) .Build(); var twitterConfig = new TwitterConfig { ConsumerKey = config["Twitter:ConsumerKey"], ConsumerSecret = config["Twitter:ConsumerSecret"], AccessToken = config["Twitter:AccessToken"], AccessTokenSecret = config["Twitter:AccessTokenSecret"] }; var twitterStream = new TwitterStream.TwitterStream(twitterConfig); twitterStream.Execute(new string[] { "netflix" }); Console.ReadKey(); }
public async Task OnLoad(object data) { if (!HasContexts) { var csa = new ConfirmServiceArgs(Strings.DoYouWantToAddANewAccount, Strings.NoAccountAdded); if (await ViewServiceRepository.Confirm(csa)) { await ViewServiceRepository.ShowAccounts(true); } } await CheckCredentials(); var loadTasks = Columns.Select(c => c.Load()); await Task.WhenAll(loadTasks); try { await TwitterConfig.QueryConfig(); } catch (Exception ex) { LogTo.WarnException("Failed to read current config from twitter", ex); } if (Configuration?.General?.CheckForUpdates == true) { bool useBetaChannel = Configuration?.General?.IncludePrereleaseUpdates == true; var channelUrl = useBetaChannel ? Constants.Updates.BetaChannelUrl : Constants.Updates.ReleaseChannelUrl; LogTo.Info("Searching for app updates..."); LogTo.Info($"Using beta channel for updates: {useBetaChannel}"); try { using (var mgr = UpdateFactory.Construct(channelUrl)) { var release = await mgr.UpdateApp(); Version newVersion = release?.Version?.Version; if (newVersion == null) { LogTo.Warn("UpdateApp returned null"); } else if (newVersion > Assembly.GetExecutingAssembly().GetName().Version) { LogTo.Info($"Updated app to {release.Version}"); Notifier.DisplayMessage(string.Format(Strings.UpdateHasBeenInstalled, release.Version), NotificationType.Information); } else { LogTo.Info("App is up to date"); } } } catch (Exception ex) when(ex.Message.Contains("Update.exe")) { } catch (Exception ex) { LogTo.WarnException("Error during update check", ex); } } await QueryRateLimit(); }
static void Main(string[] args) { string instanceName = ConfigurationManager.AppSettings["instance_name"]; string appName = "bigdatademo"; // CREATE new SERVER - this is only good for when running in embedded mode. Server cepServer = Server.Create(instanceName); // EXPOSE ENDPOINT so other clients and Event Flow Debugger can connect to it //RegisterManagementService(cepServer, "http://localhost:8080/MyStreamInsightServer"); // CREATE new APPLICATION. If one with the same name already exists, then delete it first before creating if (cepServer.Applications.ContainsKey(appName)) { cepServer.Applications[appName].Delete(); } Application cepApp = cepServer.CreateApplication(appName); // DEFINE new SOURCE, which is the Twitter Streaming API source TwitterConfig twitterConfig = ReadTwitterInputConfig(); var twitterInput = cepApp.DefineStreamable <Tweet>(typeof(TwitterFactory), twitterConfig, EventShape.Point, null); // COMPOSE a QUERY on the Twitter source we just created. var byTweetQuery = from tweet in twitterInput select tweet; // COMPOSE a QUERY to get # of tweets by topic var byTopicQuery = from tweet in twitterInput group tweet by tweet.Topic into groups from win in groups.TumblingWindow(TimeSpan.FromSeconds(_WINDOW_LENGTH)) select new TweetByTopic { Topic = groups.Key, TweetCount = win.Count(), AvgSentiment = win.Avg(t => t.SentimentScore), }; var byTotalQuery = from win in twitterInput.TumblingWindow(TimeSpan.FromSeconds(_WINDOW_LENGTH)) select new TweetSummary { TweetCount = win.Count(), AvgSentiment = win.Avg(t => t.SentimentScore), }; // DEFINE Azure DB SINK var azureDbSink = cepApp.DefineStreamableSink <Tweet>(typeof(AzureDbFactory), GetAzureDbConfig(), EventShape.Point, StreamEventOrder.ChainOrdered); // DEFINE Azure Blob Storage SINK var azureBlobSink = cepApp.DefineStreamableSink <Tweet>(typeof(AzureBlobFactory), GetAzureBlobStorageConfig(), EventShape.Point, StreamEventOrder.ChainOrdered); // DEFINE Web Socket SINK to real time dashboard for sending tweet details var byTweetDashboardSink = cepApp.DefineStreamableSink <Tweet>(typeof(WebSocketFactory), GetWebSocketConfig(QueryType.ByTweet), EventShape.Point, StreamEventOrder.ChainOrdered); // DEFINE Web Socket SINK to real time dashboard for sending aggregate data by topic var byTopicDashboardSink = cepApp.DefineStreamableSink <TweetByTopic>(typeof(WebSocketFactory), GetWebSocketConfig(QueryType.ByTopic), EventShape.Point, StreamEventOrder.ChainOrdered); //DEFINE Web Socket SINK to real time dashboard for sending total aggregate data var byTotalDashboardSink = cepApp.DefineStreamableSink <TweetSummary>(typeof(WebSocketFactory), GetWebSocketConfig(QueryType.ByTotal), EventShape.Point, StreamEventOrder.ChainOrdered); // BIND the SOURCE to the SINKS. The start the byTweetQuery using ( byTweetQuery.Bind(azureDbSink) .With(byTweetQuery.Bind(azureBlobSink)) .With(byTweetQuery.Bind(byTweetDashboardSink)) .With(byTopicQuery.Bind(byTopicDashboardSink)) .With(byTotalQuery.Bind(byTotalDashboardSink)) .Run() ) //using (byTotalQuery.Bind(byTopicDashBoardSink).With(byTweetQuery.Bind(byTotalDashboardSink)).Run()) //using (byTotalQuery.Bind(byTopicDashBoardSink).Run()) { // Wait for the user to stop the program Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine("Client is running, press Enter to exit the client"); Console.WriteLine("----------------------------------------------------------------"); Console.WriteLine(" "); Console.ReadLine(); } }
public Twitter(TwitterConfig config) { _endPoint = config.Endpoint; _apiKey = config.ApiKey; }
public TweetSaveController(IOptions <TwitterConfig> twitterConfig, ITwitterService twitterService) { _twitterConfig = twitterConfig.Value; _twitterService = twitterService; }
public Interfaces.IAuthConfig CreateConfig() { config = new TwitterConfig(); return(config); }
public override IServiceProvider ConfigureServices(IServiceCollection services) { config = services.RegisterConfiguration <TwitterConfig>(Configuration.GetSection("twitter")); return(base.ConfigureServices(services)); }
public AuthorizationManager(IOptions <TwitterConfig> twitterConfig) { _twitterConfig = twitterConfig.Value; }
private void SetAuth(TwitterConfig configuration) { Auth.SetCredentials(new TwitterCredentials(configuration.ConsumerKey, configuration.ConsumerSecret, configuration.AccessToken, configuration.AccessTokenSecret)); }
public TrackingConfigFactory(ILogger <TrackingConfigFactory> logger, TwitterConfig config, ITrackingManager manager) { Config = config ?? throw new ArgumentNullException(nameof(config)); this.manager = manager ?? throw new ArgumentNullException(nameof(manager)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
private static TextReader ReadTweets(TwitterConfig config) { const string oauthVersion = "1.0"; const string oauthSignatureMethod = "HMAC-SHA1"; // unique request details var oauthNonce = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString())); var oauthTimestamp = Convert.ToInt64( (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)) .TotalSeconds).ToString(); var resourceUrl = "https://stream.twitter.com/1.1/statuses/filter.json"; // create oauth signature var baseString = string.Format( "oauth_consumer_key={0}&oauth_nonce={1}&oauth_signature_method={2}&" + "oauth_timestamp={3}&oauth_token={4}&oauth_version={5}&track={6}", config.OAuthConsumerKey, oauthNonce, oauthSignatureMethod, oauthTimestamp, config.OAuthToken, oauthVersion, Uri.EscapeDataString(config.Keywords)); baseString = string.Concat("POST&", Uri.EscapeDataString(resourceUrl), "&", Uri.EscapeDataString(baseString)); var compositeKey = string.Concat(Uri.EscapeDataString(config.OAuthConsumerSecret), "&", Uri.EscapeDataString(config.OAuthTokenSecret)); string oauthSignature; using (var hasher = new HMACSHA1(Encoding.ASCII.GetBytes(compositeKey))) { oauthSignature = Convert.ToBase64String( hasher.ComputeHash(Encoding.ASCII.GetBytes(baseString))); } // create the request header var authHeader = string.Format( "OAuth oauth_nonce=\"{0}\", oauth_signature_method=\"{1}\", " + "oauth_timestamp=\"{2}\", oauth_consumer_key=\"{3}\", " + "oauth_token=\"{4}\", oauth_signature=\"{5}\", " + "oauth_version=\"{6}\"", Uri.EscapeDataString(oauthNonce), Uri.EscapeDataString(oauthSignatureMethod), Uri.EscapeDataString(oauthTimestamp), Uri.EscapeDataString(config.OAuthConsumerKey), Uri.EscapeDataString(config.OAuthToken), Uri.EscapeDataString(oauthSignature), Uri.EscapeDataString(oauthVersion) ); // make the request ServicePointManager.Expect100Continue = false; var postBody = "track=" + HttpUtility.UrlEncode(config.Keywords); resourceUrl += "?" + postBody; var request = (HttpWebRequest)WebRequest.Create(resourceUrl); request.Headers.Add("Authorization", authHeader); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.PreAuthenticate = true; request.AllowWriteStreamBuffering = true; request.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache); // bail out and retry after 5 seconds var tresponse = request.GetResponseAsync(); if (tresponse.Wait(5000)) { return(new StreamReader(tresponse.Result.GetResponseStream())); } else { request.Abort(); return(StreamReader.Null); } }