Welcome to

Magenic Technologies Community Blog

Sign in | Join | Help

Aaron's Technology Musings

Who let this guy on the podium?

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() } 

 

Published Sunday, March 16, 2008 3:00 PM by aarone

Filed under:

Comments

# re: An F# Political Scandal Generator @ Monday, March 17, 2008 11:11 AM

So, too much free time over the weekend?

Derik Whittaker

# re: An F# Political Scandal Generator @ Monday, March 17, 2008 5:50 PM

lol  - you think thats bad - I bought the domain scandalgenerator.com :) - its not up yet, but give it (and me) time ...

aarone

# re: An F# Political Scandal Generator @ Thursday, March 27, 2008 9:14 AM

I would normally be upset about the exclusion of Ron Paul from a list of candidates, but then again, Ron Paul would never be involved in a scandal, so that's ok :)

Ron Paul '08

# ScandalGenerator.com - The F# Based Scandal Generator Website @ Saturday, April 05, 2008 12:18 PM

Normally, I don&#39;t post here about &quot;personal&quot; projects, but since I needed a good reason

Aaron's Technology Musings

New Comments to this post are disabled
Powered by Community Server, by Telligent Systems