├── README.md ├── LICENSE └── main.py /README.md: -------------------------------------------------------------------------------- 1 | # 🌍 Internet Mood → Real-World Signal Mapper 2 | 3 | A Python tool that aggregates global internet sentiment from **news headlines** and **Reddit posts**, classifies emotions using a **transformer-based AI model**, and generates actionable **decision signals** for businesses or creators. 4 | 5 | Unlike traditional sentiment analyzers, this project synthesizes **multi-source emotional data** into a daily “emotional fingerprint,” helping you understand the **global mood** and make informed decisions. 6 | 7 | --- 8 | 9 | ## Features 10 | 11 | - Fetches **top news headlines** via NewsAPI 12 | - Scrapes **hot Reddit posts** from `r/worldnews` (or any subreddit) 13 | - Uses **HuggingFace transformer model** for multi-emotion classification: 14 | - joy, fear, anger, sadness, surprise, trust, etc. 15 | - Aggregates scores across sources into a **weighted emotional snapshot** 16 | - Generates **decision signals** based on dominant emotions 17 | - CLI-based, lightweight, and easily extendable 18 | - Can be turned into **daily mood tracker or automated alerts** 19 | 20 | --- 21 | 22 | ## Tech Stack 23 | 24 | - **Python 3.10+** 25 | - **Requests** – for HTTP requests 26 | - **PRAW** – Reddit API client 27 | - **Transformers + PyTorch** – for emotion classification 28 | - **NewsAPI** – for fetching headlines 29 | 30 | --- 31 | 32 | ## Installation 33 | 34 | 1. Clone the repo: 35 | 36 | ```bash 37 | git clone https://github.com/rahimprz/Mood-Mapper.git 38 | cd internet-mood-mapper 39 | 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2021, Anonix 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import praw 3 | from transformers import pipeline 4 | from collections import defaultdict 5 | 6 | # -------- CONFIG -------- 7 | NEWS_API_KEY = "YOUR_NEWS_API_KEY" 8 | REDDIT_CLIENT_ID = "YOUR_REDDIT_ID" 9 | REDDIT_SECRET = "YOUR_REDDIT_SECRET" 10 | REDDIT_AGENT = "mood-mapper/1.0" 11 | 12 | # -------- MODELS -------- 13 | emotion_classifier = pipeline( 14 | "text-classification", 15 | model="j-hartmann/emotion-english-distilroberta-base", 16 | return_all_scores=True 17 | ) 18 | 19 | # -------- DATA SOURCES -------- 20 | def fetch_news(): 21 | url = f"https://newsapi.org/v2/top-headlines?language=en&pageSize=10&apiKey={NEWS_API_KEY}" 22 | data = requests.get(url).json() 23 | return [a["title"] for a in data.get("articles", [])] 24 | 25 | def fetch_reddit(): 26 | reddit = praw.Reddit( 27 | client_id=REDDIT_CLIENT_ID, 28 | client_secret=REDDIT_SECRET, 29 | user_agent=REDDIT_AGENT 30 | ) 31 | texts = [] 32 | for post in reddit.subreddit("worldnews").hot(limit=10): 33 | texts.append(post.title) 34 | return texts 35 | 36 | # -------- EMOTION ENGINE -------- 37 | def analyze_emotions(texts): 38 | scores = defaultdict(float) 39 | for text in texts: 40 | results = emotion_classifier(text)[0] 41 | for r in results: 42 | scores[r["label"]] += r["score"] 43 | total = sum(scores.values()) 44 | return {k: round(v / total, 2) for k, v in scores.items()} 45 | 46 | # -------- SIGNAL -------- 47 | def generate_signal(emotions): 48 | if emotions.get("fear", 0) > 0.4: 49 | return "High anxiety detected. Avoid risky decisions." 50 | if emotions.get("joy", 0) > 0.35: 51 | return "Positive sentiment spike. Good time to launch." 52 | return "Neutral emotional state. Maintain steady operations." 53 | 54 | # -------- MAIN -------- 55 | def run(): 56 | texts = fetch_news() + fetch_reddit() 57 | emotions = analyze_emotions(texts) 58 | signal = generate_signal(emotions) 59 | 60 | print("\n🌍 Global Emotional Snapshot") 61 | print(emotions) 62 | print("\n📢 Decision Signal:") 63 | print(signal) 64 | 65 | if __name__ == "__main__": 66 | run() 67 | --------------------------------------------------------------------------------