Skip to content

Instantly share code, notes, and snippets.

View yavuzKomecoglu's full-sized avatar
:atom:
Research

Yavuz Kömeçoğlu yavuzKomecoglu

:atom:
Research
View GitHub Profile
from wordcloud import WordCloud
def generate_word_cloud_from_frequencies(freq_dict, status):
wordcloud = WordCloud(
width=800,
height=400,
background_color = 'black',
stopwords = stop_words).generate_from_frequencies(frequencies=freq_dict)
def preprocess_tweet(tweet):
processed_tweet = []
# Convert to lower case
tweet = tweet.lower()
#Clean only digits
tweet = re.sub("^\d+\s|\s\d+\s|\s\d+$", " ", tweet)
# Replaces URLs with the word URL
#tweet = re.sub(r'((www\.[\S]+)|(https?://[\S]+))', ' URL ', tweet)
def handle_emojis(tweet):
# Smile -- :), : ), :-), (:, ( :, (-:, :')
tweet = re.sub(r'(:\s?\)|:-\)|\(\s?:|\(-:|:\'\))', ' EMO_POS ', tweet)
# Laugh -- :D, : D, :-D, xD, x-D, XD, X-D
tweet = re.sub(r'(:\s?D|:-D|x-?D|X-?D)', ' EMO_POS ', tweet)
# Love -- <3, :*
tweet = re.sub(r'(<3|:\*)', ' EMO_POS ', tweet)
# Wink -- ;-), ;), ;-D, ;D, (;, (-;
tweet = re.sub(r'(;-?\)|;-?D|\(-?;)|😉', ' EMO_POS ', tweet)
# Sad -- :-(, : (, :(, ):, )-:
def preprocess_word(word):
# Remove punctuation
word = word.strip('\'"?!,.():;``')
# Convert more than 2 letter repetitions to 2 letter
# funnnnny --> funny
word = re.sub(r'(.)\1+', r'\1\1', word)
# Remove - & '
word = re.sub(r'(-|\')', '', word)
return word
from transformers import AutoModelForSequenceClassification, AutoTokenizer, pipeline
# load model
model = AutoModelForSequenceClassification.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
tokenizer = AutoTokenizer.from_pretrained("cardiffnlp/twitter-roberta-base-sentiment")
# create pipeline
sa = pipeline("sentiment-analysis", tokenizer=tokenizer, model=model)
import snscrape.modules.twitter as sntwitter
import pandas as pd
def search_hashtag(searchterm, dt_until, dt_since, lang, limit=100000):
query = "({searchterm}) lang:{lang} until:{until} since:{since}".format(searchterm=searchterm, lang=lang, until=dt_until, since=dt_since)
#query = (#Emmys2022) lang:en until:2022-09-14 since:2022-09-01
tweets = []
limit = limit
{
"adana": [
"Hatay",
"Osmaniye",
"Kahramanmaras",
"Kayseri",
"Nigde",
"Mersin"
],
"adiyaman": [
@yavuzKomecoglu
yavuzKomecoglu / check_youtube_channel_is_live.py
Last active January 28, 2020 18:27
youtube live broadcast control
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Sample use: $ python3 test_youtube_live.py -c "UCryGec9PdUCLjpJW2mgCuLw"
# {'video_id': 'j78TwQCfEzc', 'video_link': 'https://www.youtube.com/watch?v=j78TwQCfEzc', 'published_at': '2019-11-14T03:13:53.000Z', 'title': 'Seeing 2020', 'isLive': True}
import argparse
import requests
import json
ap = argparse.ArgumentParser()
@yavuzKomecoglu
yavuzKomecoglu / intenseye-detection-api.py
Last active February 12, 2022 17:47
intenseye-detection-api.py
import requests
import json
API_URL = 'https://api.intenseye.com/images/detection'
TOKEN = '{INTENSEYE_TOKEN}'
IMAGE_URL = "http://yavuzkomecoglu.com/img/hababam.jpg"
headers = {
'Content-Type': 'application/json'
from PIL import Image
from io import BytesIO
import numpy as np
import requests
import json
import cv2
TOKEN = '{INTENSEYE_TOKEN}'
IMAGE_URL = "http://yavuzkomecoglu.com/img/hababam.jpg"