After using C# to write a metadata enhancement service to enhance VOD packages for Virgin media we decided to try our hand at F# for the first time.
Obviously the code in the screenshot would be refactored for production but for a poc it is enough to show how fast a simple POC can be created in F#.
The equivalent of this in our production C# service requires serialization class plus file/data handlers to parse the same file and produce the output csv however it can be seen in this short snippet what can be achieved with a tiny amount of code in F#.
Note the input CSV contained just 2 columns
1: Provider name such as BBC, ABC etc
2: The Gracenote TMSID (asset id)
This is then parsed a call made to Gracenote, the results parsed and then written out to screen containing the episode/program id or a “Not Mapped” in lieu of missing data.
open System open FSharp.Data type ADI = XmlProvider<"D:\\Horizon4_TestDir\\TestData\\ADI.xml"> type GraceNoteProgramMapping = XmlProvider<Schema = "http://developer.tmsapi.com/files/on_update_programmappings_3.0.xsd"> [<EntryPoint>] let main argv = let inputCSV = CsvFile.Load("D:\\go-pid-paid.csv").Cache() let mappingURL = "http://on-api.gracenote.com/v3/ProgramMappings?api_key=YOURAPIKEY&" for c_row in inputCSV.Rows do let gnUrl = sprintf "%sproviderId=%s%s" mappingURL (c_row.GetColumn(0)) (c_row.GetColumn(1)) let result = GraceNoteProgramMapping.Parse(Http.RequestString(gnUrl)) if result.On.Value.ProgramMappings.ProgramMappings.Length > 0 then for _tid in result.On.Value.ProgramMappings.ProgramMappings.[0].Ids do if (_tid.Type.ToString() = "TMSId") then printf "%s,%s,%s\n" (c_row.GetColumn(0)) (c_row.GetColumn(1)) (_tid.Value) else printf "%s,%s,%s\n" (c_row.GetColumn(0)) (c_row.GetColumn(1)) "No Mapping" 0 // return an integer exit code