A4: Political Bias#

Choose Social Media Platform: Reddit | Discord | Bluesky | No Coding

In this assignment, you will be trying to calculate the average political bias and reliability of posts in a Discord channel.

Note: It may be hard to get your bot permission to read the history of a discord channel that would have interesting data. You may consider doing this assignment in another social media platform, or, if you may consider having your instructor copy content from another social media platform into discord channels you can more easily get access to.

The code you are starting with here already does a search on a (fake) discord channel and finds the reliability and political bias of url web addresses posted to the channel. You will need to add loop variables to calculate these averages (see chapter 8 practice and demos).

After you get the averages to work, you wll then try your code on other discord channels, and then you will answer some reflection questions.

First, we’ll do our normal Discord login steps.

Discord Setup#

# Load some code called "discord" that will help us work with Discord
import discord

# Load another library that helps the bot work in Jupyter Noteboook
import nest_asyncio
nest_asyncio.apply()

(optional) make a fake Discord connection with the fake_discord library

For testing purposes, we’ve added this line of code, which loads a fake version of discord, so it wont actually connect to Discord. If you want to try to actually connect to Discord, don’t run this line of code.

%run ../../../../fake_apis/fake_discord.ipynb
Fake discord is replacing the discord.py library. Fake discord doesn't need real passwords, and prevents you from accessing real discord
%run discord_keys.py
# set up Discord client with permissions to read message_contents
intents = discord.Intents.default()
intents.message_content = True 

TODO: Fill in Bias and Reliability Info#

The first step to make this work is to fill in info for the bias and reliability of different websites.

If you open media_info.csv, you’ll see a bunch of partial website links (enough to identify which site the link is for), and then blank spots for the reliability and bias of that website news sources.

You’ll use the Media Bias chart to look up one organizations ratings of bias and reliability info for each of those sites.

A small preview of the media bias chart with bias on the top axis, and reliability on the left axis.

So, open that file and then for each of the sites listed, fill in a number for the bias and reliability of the site (you’ll have to figure out how you want to turn bias and reliability into numbers). You can add additional sites as well if you want.

Load Bias and Reliability Info#

The code to load the bias and reliability info is in another file: a4-supporting_code.ipynb. You can look at that file if you are interested, but you are not required to.

# You can look in this file if you want to see more
# about how the file information is loaded
%run a4-supporting_code.ipynb

find a List of discord posts#

We can now make a bot that loads a list of discord posts.

Note: If you run this on real discord, we can’t gurantee anything about how offensive what you might find is.

# set up discord connection
client = discord.Client(intents=intents)

# TODO: put the discord channel id number below for the channel you want to use
channel_id = 123456789

# Provide instructions for what your discord bot should do once it has logged in
@client.event
async def on_ready():
    global recent_posts # Save the recent_posts variable outside our running bot
    
    # Load the discord channel you want to post to
    channel = client.get_channel(channel_id)

    # Get the latest post in the channel history
    post_history = channel.history(limit=10)
    
    #special code to turn the post_history from discord into a python list
    recent_posts = [post async for post in post_history]

    # Tell your bot to stop running
    await client.close()
    
# Now that we've defined how the bot shoould work, start running your bot
client.run(discord_token)
Fake discord is pretending to set up a client connection
Fake discord bot is fake logging in and starting to run
Fake discord bot is shutting down

Reflection tasks#

Once you get the code above working and finding an average bias and reliability, modify the search to try at least three more subreddits (and get more posts at a time, like 100). Open up the subreddit separately and look at your results, then answer the questions below.

Note: For searches, you can search for different subreddits that might have different views and post links to news articles, like: “news”, “science”, “politics”, “liberal”, “conservative”, “tech”, “BlackLivesMatter”, etc.

  1. What additional searches did you run (at least 3)?

TODO: Answer the question here

  1. When doing those searches, what were your observations about the calculations of media bias and reliability? (For example: were there a lot of urls that you didn’t measure? Do you feel like the final calculated bias and reliability match the search results?). Answer with at least 3 sentences

TODO: Answer the question here with at least 3 sentences

  1. If you could redesign the Media Bias Chart, what would you want to do (e.g., add some other dimension besides just bias/responsibility, change how it is evaluated, add more news sources, consider different countries)? Feel free to search online for critiques of the Media Bias Chart. Answer with at least 3 sentences.

TODO: Answer the question here with at least 3 sentences

  1. What might a social media companies or advertizers (including political campaigns) want to do with information on a users’ political views and susceptibility to consipracy theories? Answer with at least 3 sentences.

TODO: Answer the question here with at least 3 sentences

  1. Choose two ethics frameworks and use the frameworks to consider the different uses of the media bias and reliability information. Answer with at least 6 sentences total (e.g., 3 per framework).

TODO: Answer the question here with at least 6 sentences