Skip to content

Instantly share code, notes, and snippets.

@stigberg
Created March 28, 2014 23:37
Show Gist options
  • Save stigberg/9845277 to your computer and use it in GitHub Desktop.
Save stigberg/9845277 to your computer and use it in GitHub Desktop.
Scala eksempel på blacklisting koden
object blacklist extends App {
val blacklist = List(2,4,6,8,10)
for( id <- 1 to 10) { // for release in doc.getElementsByTagName("press_release"):
var blacklistedid = 0; // blacklistedid = ""
var bid = 0;
for (bid <- blacklist) { // for line in f:
blacklistedid = bid // blacklistedid = line.replace("\n","")
if (blacklistedid != id) { // if blacklistedid != release.getAttribute("id"):
blacklistedid = 0 // blacklistedid = ""
}
}
if (blacklistedid != 0) { // if blacklistedid != "":
println("id: " + id + ": BLACKLISTED!") // logger.debug("PM or BM with id %s is blacklisted" % (blacklistedid)); continue
} else {
println("id: " + id + ": OK!") // resten av fetchFeedElementsFromFile metoden...
}
}
}
@stigberg
Copy link
Author

En kjøring gir dette:
id: 1: OK!
id: 2: OK!
id: 3: OK!
id: 4: OK!
id: 5: OK!
id: 6: OK!
id: 7: OK!
id: 8: OK!
id: 9: OK!
id: 10: BLACKLISTED!

Burde vært dette:
id: 1: OK!
id: 2: BLACKLISTED!
id: 3: OK!
id: 4: BLACKLISTED!
id: 5: OK!
id: 6: BLACKLISTED!
id: 7: OK!
id: 8: BLACKLISTED!
id: 9: OK!
id: 10: BLACKLISTED!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment