[PYTHON] Try collecting sites all over Japan compatible with Brave browser with Twitter API

__ I hit the Twitter API with Python to collect sites that support the Brave browser. Click here for the original story. # If you tweet with "Brave compatible", I will look for it __

Brave browser compatible site @ November 2, 2020

Fumito Mizuno Closed book #Bells @ounziw "Introduction to PHP for WordPress users, carefully from the beginning." Support page

S., Masaya (me) Salaryman's private office NP-Systems

What is a Brave browser

A new Chromium-based browser developed by former Mozilla CEO. It is recognized as a high-speed browser that can ad-block, or a browser that can be thrown to content creators, but it is also a browser that receives pocket money when displaying __advertisements. In short, it's an open and secure browser that aims to allow users to manage their ads.

Regarding the Brave browser, I summarized it in this qiita article while referring to "The day when Google disappears Life after Google (by George Gilder)".

Adsense, the third monetization mechanism to replace affiliates

From the perspective of content creators, the __Brave browser is also the third monetization mechanism to replace Adsense and affiliates __. With the Brave browser, users can make money by displaying ads. And you can throw it to the site creator. As a result, it is possible to realize a mechanism on the Internet that allows musicians to receive money from the audience in front of them live on the street, and as a site creator, it will be a new means of monetization in place of Adsense and affiliates.

About this article

Therefore, in this article, I introduced how to register as a creator with the Brave browser. However, in reality, there are still few sites that have registered as creators in the Brave browser. So, in this article, I would like to introduce the sites in Japan that are registered in the Brave browser, which is the third monetization mechanism (reckless, but only enough sites to do that). I don't expect it).

However, since this is a programming information sharing site, it violates the policy, so I would like to introduce the code to get tweets with the hashtag "#brave compatible" via Twitter API in Python. I will. And in the form of summarizing the results, I would like to introduce sites all over Japan that have been registered as creators in the Brave browser.

__ After registering your site as a creator in your Brave browser, try posting on Twitter with the hashtag "#brave compatible". We plan to update the article every 24 hours! __

Now I would like to get tweets in Python.

Apply for Twitter API

First of all, you have to get a token of Twitter API, but this is quite troublesome. You can use it after applying and waiting on the site called Twitter Developer. It may be better to apply and do something else and wait. Apply by referring to this site.

https://www.itti.jp/web-direction/how-to-apply-for-twitter-api/

Prepare a Python wrapper that hits the Twitter API

Once you have the token, all you have to do is hit the API with it. It seems that a library called tweety was often used as a Python Wrapper, but I didn't work (Python 3.7.3, Mac). So I used the code in this article. The program was very clean and too divine.

https://qiita.com/newt0/items/243b6f98a31433d2faaf

I created this kind of code.

main.py


Class God article code():
  ''
  ''

def get_tweets():
    getter = TweetsGetter.bySearch('brave browser')#The keyword you want to search here.
    df = pd.DataFrame()
    for tweet in getter.collect(total = 50):
        print(tweet)
        created_at = tweet['created_at']#'Sun Oct 11 06:53:43 +0000 2020'
        year = created_at[-4:]
        time = created_at[-19:-11]
        day = created_at[-22:-20]
        month = {'Jan':'1','Feb':'2','Mar':'3','Apr':'4','May':'5','Jun':'6','Jul':'7','Aug':'8','Sep':'9','Oct':'10','Nov':'11','Dec':'12'}[created_at[4:7]]
        when =  datetime.strptime('%s/%s/%s %s'%(year,month,day,time),'%Y/%m/%d %H:%M:%S',)
        when = when.timestamp()
        when = datetime.fromtimestamp(when+3600*9)
        temp = pd.DataFrame({
        'id':[tweet['id']],
        'when':[when],
        'text':[tweet['text']],
        })
        df = pd.concat([df,temp],axis=0).reset_index(drop=True)
    with open("path/data.csv", mode="w", encoding="cp932", errors="ignore") as f:
        #Write to a file object with pandas
        df.to_csv(f,index=False,encoding='shift-jis')
    return df

if __name__ == '__main__':
    df = get_tweets()

The result of moving

The result looks like this. I made it csv.

スクリーンショット 2020-11-01 22.42.00.jpg

Try collecting sites all over Japan that support Brave browser

After that, just extract the URL from the result of csv, and you can get the site compatible with Brave browser. By the way, as of November 1st, there was no "#brave compatible" site yet. I would like to post the first result around Saturday and Sunday next week.

The Brave browser is a very interesting browser, so let's all create a new internet! Please try tweeting it.

Click here for Brave browser

Recommended Posts

Try collecting sites all over Japan compatible with Brave browser with Twitter API
Collecting information from Twitter with Python (Twitter API)
Try hitting the Twitter API quickly and easily with Python
Use Twitter API with Python
Try using the Twitter API
Try using the Twitter API
Support yourself with Twitter API
Successful update_with_media with twitter API