Skip to content

Instantly share code, notes, and snippets.

@edubey
edubey / Text-summarization.py
Created December 22, 2018 15:09
Text Summarizer in Python
#!/usr/bin/env python
# coding: utf-8
from nltk.corpus import stopwords
from nltk.cluster.util import cosine_distance
import numpy as np
import networkx as nx
def read_article(file_name):
file = open(file_name, "r")
@edubey
edubey / bag-of-word-vectors.py
Created December 2, 2018 18:15
Code to generate bag of word vectors in Python
# import statments
import numpy
import re
'''
Tokenize each the sentences, example
Input : "John likes to watch movies. Mary likes movies too"
Ouput : "John","likes","to","watch","movies","Mary","likes","movies","too"
'''
def tokenize(sentences):
@edubey
edubey / Multiple-story-medium.js
Created November 18, 2018 09:13
Scrap Multiple Story from a Publisher Page
var i = 0,
maxCount = 5;
var storyInterval = setInterval(() => {
document.querySelectorAll(".js-trackedPost>a")[i].click()
setTimeout(() => {
console.log("Title : ", document.getElementsByClassName("graf--title")[i].innerText);
p = document.getElementsByClassName("ui-xs-clamp2")[0]
console.log("Profile Description : ", p ? p.innerText : "");
history.back()
}, 2000);
@edubey
edubey / Single Story.js
Created November 17, 2018 14:54
Save data from console for medium story
var storyPath = window.location.href;
// Console API to clear console before logging new data
console.API;
if (typeof console._commandLineAPI !== 'undefined') {
console.API = console._commandLineAPI; //chrome
} else if (typeof console._inspectorCommandLineAPI !== 'undefined') {
console.API = console._inspectorCommandLineAPI; //Safari
} else if (typeof console.clear !== 'undefined') {
@edubey
edubey / console-save.js
Created November 17, 2018 14:25
Save the data from browser console in a file
console.save = function (data, filename) {
if (!data) {
console.error('Console.save: No data')
return;
}
if (!filename) filename = 'story.json'
if (typeof data === "object") {
data = JSON.stringify(data, undefined, 4)
@edubey
edubey / story-element.js
Created November 17, 2018 14:22
Extract Data from a medium story
// Extracts high level details of current story
function getCurrentStoryDetail() {
console.API.clear();
storyObj = {};
storyObj.title = document.getElementsByClassName("graf--title")[0].innerText;
storyObj.count = document.getElementsByClassName("js-multirecommendCountButton")[0].innerText;
storyObj.name = document.getElementsByClassName("ds-link--styleSubtle")[0].innerText;
storyObj.imageUrl = document.getElementsByClassName("avatar-image")[0].src;
storyObj.profile = document.getElementsByClassName("ui-xs-clamp2")[0].innerText;