-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrape.groovy
More file actions
executable file
·58 lines (48 loc) · 1.64 KB
/
scrape.groovy
File metadata and controls
executable file
·58 lines (48 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import groovy.json.JsonSlurper
import static groovy.io.FileType.FILES
moduleFile = new File("./module.txt")
indexDir = "./output" // Needs to be changed according to workspace setting
if(moduleFile.exists()) {
moduleJson = new JsonSlurper().parseText(moduleFile.text)
moduleName = moduleJson.get("id")
println "Scraping data from " + moduleName
moduleSrc = moduleFile
moduleDst = new File(indexDir.toString() + "/module.txt")
moduleDst << moduleSrc.text
println "Fetched module data"
dir = new File('./')
println "Searching for README file..."
readmeFound = 0
dir.eachFile { file ->
if(file.name.endsWith('.md') || file.name.endsWith('.markdown') || file.name.endsWith('.MD') || file.name.endsWith('.MARKDOWN')) {
println "README Found."
readmeSrc = new File("./" + file.toString())
readmeDst = new File(indexDir.toString() + "/README.md")
readmeDst << readmeSrc.text
println "Fetched README data."
readmeFound += 1
}
}
if(readmeFound == 0) {
println "README file not found, skipping the current step."
}
logoSrc = new File("./logo.png")
coverSrc = new File("./cover.png")
if(logoSrc.exists()) {
logoDst = new File(indexDir.toString() + "/logo.png")
logoDst << logoSrc.bytes
println "Fetched logo image."
} else {
println "Logo image not found, skipping the current step."
}
if(coverSrc.exists()) {
coverDst = new File(indexDir.toString() + "/cover.png")
coverDst << coverSrc.bytes
println "Fetched cover image."
} else {
println "Cover image not found, skipping the current step."
}
println "Finished scrapping " + moduleName
} else {
println "The following repository is not a module."
}