예제 #1
0
        static void Rotina(Object o)
        {
            try
            {
                Auth.SetUserCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");

                // Get json directly
                var tweetsJson = SearchJson.SearchTweets("MINHA_PALAVRA_CHAVE");

                // Get json from ITweet objects
                var tweets = Search.SearchTweets("testetadepe");
                // JSON Convert from Newtonsoft available with Tweetinvi
                var json = JsonConvert.SerializeObject(tweets.Select(x => x.TweetDTO));
                var tweetDTOsFromJson = JsonConvert.DeserializeObject <ITweetDTO[]>(json, JsonPropertiesConverterRepository.Converters);
                var tweetsFromJson    = Tweet.GenerateTweetsFromDTO(tweetDTOsFromJson);

                foreach (ITweetDTO tw in tweetDTOsFromJson)
                {
                    DataTable tabela = RetornaTabela("SELECT * FROM TWEET WHERE ID=" + tw.Id.ToString());

                    string id   = tw.Id.ToString();
                    string user = tw.CreatedBy.ToString();

                    if (tabela.Rows.Count == 0)
                    {
                        InsereTweet(id, user);

                        Tweet.PublishTweet("@" + tw.CreatedBy + " Olá, meu nome é Liza, tudo bem? Você sabia que  pode fazer sua reclamação comigo através deste link?  https://m.me/FiscalizaObra  #" + id.ToString());
                    }
                }
            }
            catch
            {
            }
        }
예제 #2
0
 private void DownloadMedia(SearchJson page)
 {
     try
     {
         foreach (var post in page.SearchRoute.SearchApiResponse.Response.Posts.Data)
         {
             if (post.ObjectType != "post")
             {
                 continue;
             }
             if (!CheckIfWithinTimespan(post.Timestamp))
             {
                 continue;
             }
             foreach (var content in post.Content)
             {
                 DownloadMedia(content, post.Id, post.Timestamp);
             }
             AddToJsonQueue(new TumblrCrawlerData <DataModels.TumblrSearchJson.Data>(Path.ChangeExtension(post.Id, ".json"), post));
         }
     }
     catch (TimeoutException timeoutException)
     {
         HandleTimeoutException(timeoutException, Resources.Crawling);
     }
     catch
     {
     }
 }
        private void UpdateTweets()
        {
            string tweetFeedInJson = SearchJson.SearchTweets("dotnetconfsg");

            var tweetFeed = JsonConvert.DeserializeObject <TweetFeed>(tweetFeedInJson);

            this.DataContext = new Tweets(tweetFeed, isShowingAllTweets);
        }
예제 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Connecting to twitter.com...");
            var jsonResult = SearchJson.SearchTweets("tweetinvi");

            TwitterCredentials.CreateCredentials("490599333-RkRqjA4Icbh0PVyQdllZyoD0Y2S6Cjc5F2eo6Tb6", "727vXKJyQ7bGoTjDNI3gJR5gJ4OUShsJhazaYDDkqs6jt", "XT6Xu6sNxnBxeDODPIawUA", "rI1aWSVDcNN4XnmUofkkaIvbzhTivkL0HSeonleDeZY");
            Console.WriteLine(ExceptionHandler.GetLastException().StatusCode);
            Console.WriteLine(ExceptionHandler.GetLastException().TwitterDescription);
            Console.WriteLine(ExceptionHandler.GetLastException().TwitterExceptionInfos.First().Message);
            Console.ReadKey();
        }
예제 #5
0
        public JsonResult GetListProducts()
        {
            List <SearchJson> searches = new List <SearchJson>();
            List <Product>    products = ProductDAO.Instance.GetAllProducts();

            foreach (Product product in products)
            {
                SearchJson search = new SearchJson();
                search.Value = product.Name;
                search.Data  = product.Id;
                searches.Add(search);
            }
            return(Json(searches));
        }
예제 #6
0
        public SearchResult Search(string keyword, SearchType type = SearchType.Song, int limit = 30, int offset = 0) {
            var url = "http://music.163.com/weapi/cloudsearch/get/web";
            var data = new SearchJson {
                s = keyword,
                type = (int) type,
                limit = limit,
                offset = offset,
            };

            string raw = CURL(url, Prepare(JsonConvert.SerializeObject(data)));

            var DeserialedObj = JsonConvert.DeserializeObject<SearchResult>(raw);

            return DeserialedObj;
        }
예제 #7
0
        private async Task CrawlPageAsync()
        {
            try
            {
                string document = await GetSearchPageAsync();

                string     json        = extractJsonFromSearch.Match(document).Groups[1].Value;
                SearchJson result      = ConvertJsonToClassNew <SearchJson>(json);
                string     nextUrl     = result.ApiUrl + result.SearchRoute.SearchApiResponse.Response.Posts.Links.Next.Href;
                string     bearerToken = result.ApiFetchStore.APITOKEN;

                DownloadMedia(result);
                while (true)
                {
                    if (CheckIfShouldStop())
                    {
                        return;
                    }
                    CheckIfShouldPause();

                    document = await GetRequestAsync(nextUrl, bearerToken);

                    TumblrSearchApi apiresult = ConvertJsonToClassNew <TumblrSearchApi>(document);
                    DownloadMedia(apiresult);

                    if (apiresult.Response.Posts.Links == null)
                    {
                        return;
                    }
                    nextUrl = result.ApiUrl + apiresult.Response.Posts.Links.Next.Href;
                }
            }
            catch (TimeoutException timeoutException)
            {
                HandleTimeoutException(timeoutException, Resources.Crawling);
            }
            catch (Exception e)
            {
                Logger.Error("TumblrSearchCrawler.CrawlPageAsync: {0}", e);
            }
            finally
            {
                semaphoreSlim.Release();
            }
        }
예제 #8
0
        public static void Search_SimpleTweetSearch()
        {
            var searchParameter = Search.CreateTweetSearchParameter("@timesnow");

            searchParameter.MaximumNumberOfResults = 0000;
            var tweets = SearchJson.SearchTweets(searchParameter);

            System.IO.StreamWriter file = new System.IO.StreamWriter("timesnow.json", true);
            foreach (var tweet in tweets)
            {
                String replacedString  = tweet.Replace("{\"statuses\":[", "");
                string replacedString2 = replacedString.Replace("},{\"metadata\":", "}\n{\"metadata\":");
                string removedString   = replacedString2.Remove(replacedString2.IndexOf("],\"search_metadata"));
                file.WriteLine(removedString);
                file.Flush();
            }
            file.Close();
        }
예제 #9
0
 private void DownloadMedia(SearchJson page)
 {
     try
     {
         foreach (var post in page.SearchRoute.SearchApiResponse.Response.Posts.Data)
         {
             if (post.ObjectType != "post")
             {
                 continue;
             }
             if (!CheckIfWithinTimespan(post.Timestamp))
             {
                 continue;
             }
             int index = -1;
             foreach (var content in post.Content)
             {
                 Post data = new Post()
                 {
                     Date              = DateTimeOffset.FromUnixTimeSeconds(post.Timestamp).DateTime.ToString("yyyyMMddHHmmss"),
                     Type              = ConvertContentTypeToPostType(content.Type),
                     Id                = post.Id,
                     Tags              = new List <string>(post.Tags),
                     Slug              = post.Slug,
                     RegularTitle      = post.Summary,
                     RebloggedFromName = "",
                     ReblogKey         = post.ReblogKey,
                     UnixTimestamp     = post.Timestamp,
                     Submitter         = post.BlogName
                 };
                 index += (post.Content.Count > 1) ? 1 : 0;
                 DownloadMedia(content, data, index);
             }
             AddToJsonQueue(new TumblrCrawlerData <DataModels.TumblrSearchJson.Data>(Path.ChangeExtension(post.Id, ".json"), post));
         }
     }
     catch (TimeoutException timeoutException)
     {
         HandleTimeoutException(timeoutException, Resources.Crawling);
     }
     catch
     {
     }
 }
예제 #10
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = inflater.Inflate(Resource.Layout.movies_list_fragment, container, false);

            if (_movies == null)
            {
                var titlesNameFile = Path.Combine(Environment.ExternalStorageDirectory.Path,
                                                  Environment.DirectoryDownloads,
                                                  "MoviesList.json");
                var test = view.FindViewById <TextView>(Resource.Id.test_view);

                if (!File.Exists(titlesNameFile))
                {
                    test.Text = "File with movie titles not found. It should be in downloads folder.";
                    return(view);
                }

                if ((ContextCompat.CheckSelfPermission(Context, Manifest.Permission.WriteExternalStorage) !=
                     (int)Permission.Granted) ||
                    (ContextCompat.CheckSelfPermission(Context, Manifest.Permission.ReadExternalStorage) !=
                     (int)Permission.Granted))
                {
                    RequestPermissions(
                        new[]
                        { Manifest.Permission.ReadExternalStorage, Manifest.Permission.WriteExternalStorage }, 1);
                }

                var titlesJson = File.ReadAllText(titlesNameFile);
                _movies = JsonSerializer.Deserialize <SearchJson>(titlesJson);
            }

            foreach (var movie in _movies.Search)
            {
                MovieFragment fragment =
                    MovieFragment.NewInstance(movie.Title, movie.Year, movie.Type, movie.Poster, movie.imdbID);

                FragmentManager.BeginTransaction()
                .Add(Resource.Id.movieContainer, fragment)
                .Commit();
            }

            return(view);
        }