An F# Political Scandal Generator
Not content to remain silent this political season, as a service to all the campaigns, I am providing some source-code for a "scandal generator" - an automated tool the candidates can use to generate headlines and save needed campaign donation funds.
Of course, this could be put behind a website, an automailer to press organizations, or used in a number of other clever ways. Basically, you feed it a file that represents a madlib (line 1 is the headline, the rest of the file is the body) - and it produces a "scandal" object that should have everything you need.
Oh, and the cool part, it is written in F# :)
Have fun!
#light
module AaronErickson.ScandalGeneratorEngine
open System
open System.IO
let private probabilityTest (range:int,prob:int) =
Random().Next(range) < prob
(* various named probabilities *)
let private isImportant() = probabilityTest (100,50)
(* our politicians *)
type Politician = { Name: string; FullName: string; ProNoun: string; HomeTown: string}
(* opposing politicians *)
type OpposingPoliticians = { Politician: Politician; Opponent: Politician }
(* story type *)
type Scandal = { Headline: string; Body: string; IsImportant: bool }
let private obama = { Name="Obama"; FullName="Barack Obama"; ProNoun="his"; HomeTown="Chicago" }
let private clinton = { Name="Clinton"; FullName="Hillary Clinton"; ProNoun="her"; HomeTown="New York" }
let private mccain = { Name="McCain"; FullName="John McCain"; ProNoun="his"; HomeTown="Phoenix" }
let private getPoliticians() =
match Random().Next(3) with
| 0 -> { Politician=obama; Opponent=clinton }
| 1 -> { Politician=clinton; Opponent=obama }
| 2 -> { Politician=mccain; Opponent=obama }
| _ -> { Politician=mccain; Opponent=clinton }
let private getPressAgency() =
match Random().Next(3) with
| 0 -> "The Onion"
| 1 -> "The Drudge Report"
| 2 -> "Fox News"
| _ -> "The Associated Press"
(* generates a single scandal composed of a headline, a story, and whether it is considered 'important' *)
let GenerateScandal (templateFile:String) =
use reader = new StreamReader(templateFile)
let templateTextHeadline = reader.ReadLine()
let templateText = reader.ReadToEnd()
let politicians = getPoliticians()
let headlineWithPoliticians = templateTextHeadline.Replace("%politician%",politicians.Politician.Name)
let storyWithPoliticians = templateText.Replace("%politician%",politicians.Politician.Name)
.Replace("%fullpolitician%",politicians.Politician.FullName)
.Replace("%opposingpolitician%",politicians.Opponent.Name)
.Replace("%pronoun%",politicians.Politician.ProNoun)
.Replace("%hometown%",politicians.Politician.HomeTown)
.Replace("%pressagency%",getPressAgency())
{ Headline = headlineWithPoliticians; Body = storyWithPoliticians; IsImportant = isImportant() }