├── views ├── styles.css └── index.ejs ├── hello.js ├── public └── logo1.png ├── package.json ├── app.js └── README.md /views/styles.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hello.js: -------------------------------------------------------------------------------- 1 | var yummy = { 2 | // ENTER YOUR KEYS FROM RAPID API HERE 3 | } 4 | 5 | module.exports = yummy; -------------------------------------------------------------------------------- /public/logo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wimpywarlord/Webscraping-and-sentimental-analysis/HEAD/public/logo1.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dhweekly-2.0", 3 | "version": "1.0.0", 4 | "description": "Lets use analyse the public sentiment about X Æ A-12 Musk.", 5 | "main": "app.js", 6 | "scripts": { 7 | "dev": "nodemon app.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/wimpywarlord/Dhweekly-2.0.git" 13 | }, 14 | "author": "", 15 | "license": "ISC", 16 | "bugs": { 17 | "url": "https://github.com/wimpywarlord/Dhweekly-2.0/issues" 18 | }, 19 | "homepage": "https://github.com/wimpywarlord/Dhweekly-2.0#readme", 20 | "dependencies": { 21 | "body-parser": "^1.19.0", 22 | "cheerio": "^1.0.0-rc.3", 23 | "ejs": "^3.1.2", 24 | "express": "^4.17.1", 25 | "nodemon": "^2.0.3", 26 | "request": "^2.88.2", 27 | "unirest": "^0.6.0" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const bodyParser = require("body-parser"); 3 | const cheerio = require('cheerio'); 4 | const request = require('request'); 5 | var unirest = require("unirest"); 6 | var yummy = require("./hello") 7 | 8 | 9 | var req = unirest("POST", "https://microsoft-azure-text-analytics-v1.p.rapidapi.com/sentiment"); 10 | 11 | const app = express(); 12 | app.use(express.static("public")); 13 | app.use(bodyParser.urlencoded({ extended: true })); 14 | 15 | req.headers(yummy); 16 | 17 | req.type("json"); 18 | var total_final_sentiment = 0; 19 | var counter = 0; 20 | 21 | 22 | // MIDDLEWARE 23 | app.use(bodyParser.json()); 24 | 25 | // LOGIC 26 | app.get("/", function (req, res) { 27 | res.render("index.ejs", { 28 | bg: "/logo1.png", 29 | status: "" 30 | }); 31 | }); 32 | 33 | app.post("/home", function (req_1, res) { 34 | console.log(req_1.body.userName, "*"); 35 | request(req_1.body.userName, (err, resp, body) => { 36 | // console.log(object); 37 | const $ = cheerio.load(body); 38 | $('p.TweetTextSize').each((index, item) => { 39 | 40 | 41 | 42 | counter = counter + 1; 43 | 44 | 45 | if (typeof item.children[0].data !== "undefined") { 46 | console.log(item.children[0].data, "&"); 47 | } 48 | req.send({ 49 | "documents": [ 50 | { 51 | "language": "en", 52 | "id": "string", 53 | "text": item.children[0].data 54 | } 55 | ] 56 | }); 57 | 58 | req.end(function (res) { 59 | if (res.error) throw new Error(res.error); 60 | 61 | if (typeof res.body.documents[0] !== "undefined") { 62 | console.log(res.body.documents[0], "%"); 63 | console.log(res.body.documents[0].score); 64 | total_final_sentiment = total_final_sentiment + res.body.documents[0].score; 65 | } 66 | }); 67 | }); 68 | 69 | } 70 | 71 | ); 72 | 73 | setTimeout(() => { 74 | answer = total_final_sentiment / counter; 75 | console.log(total_final_sentiment, "$", answer); 76 | var string_ans = ''; 77 | console.log(typeof answer); 78 | if (answer > 0.6 && 1 >= answer) { 79 | console.log("21312"); 80 | string_ans = "POSITIVE" 81 | } 82 | else if (answer > 0.4 && 0.6 >= answer) { 83 | console.log("ashdjaskd"); 84 | string_ans = "NEUTRAL" 85 | } 86 | else { 87 | console.log("1231asdas"); 88 | string_ans = "NEGATIVE" 89 | } 90 | 91 | console.log(string_ans, ")()()"); 92 | res.render("index.ejs", { 93 | bg: "/logo1.png", 94 | status: string_ans 95 | }); 96 | }, 10000); 97 | }); 98 | 99 | 100 | 101 | // LISTEN 102 | const port = process.env.PORT || 5500; 103 | 104 | app.listen(port, () => console.log(`server started on ${port}`)); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # World's reaction to naming your child X AE A-12. 2 | 3 | [![Stay Motivated](https://img.shields.io/badge/Stay-Motivated-teal.svg?style=for-the-badge)](https://github.com/wimpywarlord/Mess_It_Up) 4 | [![Think Big](https://img.shields.io/badge/Think-Big-orange.svg?style=for-the-badge)](https://www.linkedin.com/in/kshitijdhyani/) 5 | [![Work Hard](https://img.shields.io/badge/Work-Hard-blue.svg?style=for-the-badge)](https://github.com/wimpywarlord) 6 | 7 | Internet's favourite billionaire, Elon Musk is back to challenging conventions. This time, he has named his new-born son "X AE A-12" and as you have cleverly deduced, the internet is abuzz with opinions. 8 | 9 | Join Vinnovate IT, at our Live Webinar, as we demonstrates novel Web Scraping techniques to dig up these opinions across Twitter and sentimentally analyse them. Great content awaits. 10 | 11 | Link to youtube tutorial : https://www.youtube.com/watch?v=QY_ky8zaN38&t=13s 12 | 13 | ## Getting Started 14 | 15 | [![THINK](https://img.shields.io/badge/Stay-Motivated-teal.svg?style=for-the-badge)](https://github.com/wimpywarlord/Mess_It_Up) 16 | [![MAKE](https://img.shields.io/badge/Think-Big-orange.svg?style=for-the-badge)](https://www.linkedin.com/in/kshitijdhyani/) 17 | [![SELL](https://img.shields.io/badge/Work-Hard-blue.svg?style=for-the-badge)](https://github.com/wimpywarlord) 18 | 19 | 20 | 21 | Its quite simple, just follow the following steps. 22 | 23 | >You will be needing your own api keys. 24 | 25 | Start with cloning the repository in the desired directory by typing below in the command prompt: 26 | 27 | ``` 28 | git clone 29 | ``` 30 | 31 | Open command prompt and type 32 | ``` 33 | npm run dev 34 | ``` 35 | 36 | ### Prerequisites 37 | 38 | All you need is a knack for learning. 39 | 40 | > Your life will flash in front of your eyes one day,make sure its worth watching. 41 | 42 | If you are just getting started with GitHub then I recommended you to read [this](https://github.com/wimpywarlord/first-contributions/blob/master/README.md) document. This is for when you look forward to making small changes and pull requests. 43 | 44 | In case you want a comprehensive understanding of GitHub and want to become a long term contributor to this project, I recommend reading [this]( https://gist.github.com/Chaser324/ce0505fbed06b947d962) document. 45 | 46 | 47 | 48 | ### Installing 49 | 50 | Optionally I recommend you to download **Sublime text** 3.Its a amazing free editor from [here](https://www.sublimetext.com/3). 51 | 52 | 53 | ## Built With 54 | 55 | [![Built with Love](https://forthebadge.com/images/badges/built-with-love.svg)](https://www.linkedin.com/in/kshitijdhyani/) [![KSHITIJ DHYANI](https://forthebadge.com/images/badges/makes-people-smile.svg)](https://www.linkedin.com/in/kshitijdhyani/) 56 | 57 | Api's from rapid Api : https://rapidapi.com/ 58 | 59 | Web scraping tool : https://cheerio.js.org/ 60 | 61 | Build with love and some Javascript. 62 | 63 | ## Contributing 64 | 65 | Help us make the site better in any way possible. 66 | 67 | Send Clear crisp and helpfull PRs. 68 | 69 | ## I'm a social animal! 70 | 71 | So connect with me and share your experience. 72 | 73 | I would love to interact with this world full of amazing people such as you. 74 | 75 |       76 | -------------------------------------------------------------------------------- /views/index.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | login 8 | 102 | 103 | 104 | 105 | 106 |
107 | 108 | <% if(status === "") 109 | { 110 | %> 111 |

112 | 113 | 114 |

115 |

116 |

117 | 118 |
119 |

120 |

121 | 122 |

123 | <%} 124 | else {%> 125 |
126 | <%=status%> 127 |
128 | <%}%> 129 |
130 | 133 | 134 | 136 | 146 | 147 | --------------------------------------------------------------------------------