FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Añadir archivos para _wordcloud_ de tweets by nicoguaro · Pull Request #1 · ColombiaPython/scripts · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .md  (2) .png  (2) .py  (2) .txt  (3) All 4 file types selected
Only manifest files
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 7 additions & 0 deletions AUTHORS.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Desarrolladores principales
- Gonzalo Peña-Castellanos
- Nicolás Guarín-Zapata

# Contribuciones

Ninguna aún.
39 changes: 38 additions & 1 deletion README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
# scripts
# Scripts para ColombiaPython

Una colección de _scripts_ para realizar diferentes tareas de procesamiento
relacionadas con ColombiaPython.

## pycon-metricas

Esta carpeta contiene scripts para el procesamiento de datos relacionados
con PyCon Colombia 2018. Actualmente contiene scripts para la generación
de nubes de palabras (_wordclouds_) a partir de los _tweets_ asociados al
evento.

## Dependencias

Los scripts pueden ser ejecutados en los dialectos 2 y 3 de Python
y requieren de los siguientes paquetes:

- ``beautifulsoup4``.
- ``wordcloud``.

### Web scrapping
El script ``pycon_tweets_scrapping.py`` genera un archivo de texto plano
a partir de un conjunto de tweets. En nuestro caso, se usó un archivo
html con esta información que no se incluye por razones de derechos de
autor. Para ejecutar este script

python pycon_tweets_scrapping.py


### Generación de la nube de palabras

El script ``pycon_tweets_scrapping.py`` genera una imagen a partir de:

- **Texto plano:** del cual se obtienen las palabras.
- **Stopwords:** que define las palabras que no se incluirán en la
visualización.
- **Máscara:** imagen en blanco y negro con la silueta para la nube
de palabras.

27 changes: 27 additions & 0 deletions pycon-metricas/pycon_tweets_scrapping.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
"""PyCon Colombia 2018 tweets!"""

# Standard library imports
import io
import os

# Third party imports
from bs4 import BeautifulSoup


HERE = os.path.abspath(os.path.dirname(__file__))
FILE_IN = os.path.join(HERE, '#PyConColombia2018_Twitter.html')
FILE_OUT = os.path.join(HERE, 'tweet_texts.txt')

# Load data
with io.open(FILE_IN, 'r') as f:
html_doc = f.read()

# Process data
soup = BeautifulSoup(html_doc, 'html.parser')
tweet_divs = soup.find_all('div', 'js-tweet-text-container')
texts = [tweet_div.text for tweet_div in tweet_divs]

# Save data
with io.open(FILE_OUT, 'w', encoding='utf-8') as f:
html_doc = f.write(''.join(texts))
51 changes: 51 additions & 0 deletions pycon-metricas/pycon_tweets_wordcloud.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# -*- coding: utf-8 -*-
"""PyCon Colombia 2018 tweets wordcloud"""

# Standard library imports
from os import path

# Third party imports
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
from wordcloud import WordCloud, STOPWORDS

HERE = path.dirname(__file__)
FILE_IN = path.join(HERE, 'tweet_texts.txt')
FILE_OUT = path.join(HERE, 'pycon_wordcloud.png')
STOP_ES = path.join(HERE, 'stopwords_spanish.txt')
MASK = path.join(HERE, "python_mask.png")
STOP_EXTRA = ["PyConColombia2018", "pyconcolombia", "twitter", "pic",
"Pycon2018", "Python", "https", "PyCon2018pic", "ThePSF",
"PyConColombia2019", "PyCon", "ColombiaPython", "bit", "ly",
"goo", "gl", "1er", "día", "hoy", "today", "mañana",
"Segundo", "tarde", "primer", "year", "siempre"]
BW = "white"

# Read files
text = open(FILE_IN).read()
python_mask = np.array(Image.open(MASK))
with open(STOP_ES) as f:
stopwords = set(f.read().split())

# Add stopwords
stopwords.update(STOPWORDS)
stopwords.update(STOP_EXTRA)


# Generate word cloud
wc = WordCloud(background_color=BW,
max_words=1000,
mask=python_mask,
width=3000,
height=3033,
stopwords=stopwords)
wc.generate(text)

# Store to file
wc.to_file(FILE_OUT)

# show
plt.imshow(wc, interpolation='bilinear')
plt.axis("off")
plt.show()
Binary file added pycon-metricas/pycon_wordcloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Binary file added pycon-metricas/python_mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
Loading

Back | FazBrowse Home | New Git URL