Twitter Data Collection Script (MexPol.py) for Mexican Political Propaganda Analysis with Large Language Models
Description
This Python script was developed to collect Twitter data during the 2018 Mexican presidential election campaign. It tracks mentions and tweets related to the main presidential candidates (@JoseAMeadeK, @RicardoAnayaC, @lopezobrador_, and @JaimeRdzNL) by filtering the Twitter stream API. The collected data includes tweet IDs, user screen names, URLs, follower counts, timestamps (both in UTC and Mexico City time), tweet content, source, geographical coordinates (when available), and user location information. This script was created as part of the research project "In-Context Learning for Misinformation Detection: Detecting Political Propaganda on Twitter Mexico using Large Language Model Meta AI." The primary goal was to gather public Twitter data related to Mexican political discourse during the 2018 presidential election for subsequent analysis of misinformation patterns and political propaganda. Data Privacy: This script only collected tweets that were publicly accessible (i.e., those without privacy restrictions set by users). No private communications or protected tweets were accessed or stored.
Files
Steps to reproduce
Technical Details: Written in Python 2.x Uses the Twitter API via the twitter Python package Authenticates using OAuth credentials Filters the global Twitter stream for specific candidate mentions Converts UTC timestamps to Mexico City local time Outputs collected data in tab-separated format API Restrictions: Due to this code was developed in 2018 when Twitter's API was more openly accessible. As of 2025, this script cannot be run as-is due to significant changes in X's (formerly Twitter) API access policies, authentication requirements, and rate limitations.