Created
September 14, 2023 20:47
-
-
Save Prajwalprakash3722/d8ebd5fa32f0cea84bd51ea7685d9e83 to your computer and use it in GitHub Desktop.
Count the number of Series & Movies you have watched, Download the NetflixViewingHistory from your account/profile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/csv" | |
"fmt" | |
"os" | |
"regexp" | |
) | |
func main() { | |
file, err := os.Open("NetflixViewingHistory.csv") | |
if err != nil { | |
fmt.Println("Error opening CSV file:", err) | |
return | |
} | |
fmt.Println("Successfully opened CSV file") | |
defer file.Close() | |
reader := csv.NewReader(file) | |
seriesCount := 0 | |
regex := regexp.MustCompile(`^([^:]+):`) | |
seriesMap := make(map[string]bool) | |
for { | |
record, err := reader.Read() | |
if err != nil { | |
break | |
} | |
title := record[0] | |
matches := regex.FindStringSubmatch(title) | |
if len(matches) > 1 { | |
seriesName := matches[1] | |
seriesMap[seriesName] = true | |
} | |
} | |
seriesCount = len(seriesMap) | |
fmt.Printf("Total movies/series watched: %d\n", seriesCount) | |
fmt.Println("Series watched:") | |
for seriesName := range seriesMap { | |
fmt.Println(seriesName) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment