-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataInput.ps1
172 lines (147 loc) · 4.92 KB
/
dataInput.ps1
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# Indefinately loop until ^C is pressed
For (; ; ) {
Clear-Host; $artist = ""; $artistUrl = ""
# Load index.tsv
$csv = Import-Csv -Path index.tsv -Delimiter "`t"
# Guess current new Hexadecimal ID from last array
$last = $csv[$csv.Count - 1]
$lastId = $last.ID
# Convert to decimal
$lastId = [Convert]::ToInt32($lastId, 16)
$lid = $lastId
# Increment by 1
$lastId = $lastId + 1
# Convert to hexadecimal
$newId = '{0:X}' -f $lastId
# Create new array
Do {
$id = Read-Host "DB ID ($newId)"
if (!$id) {
$id = $newId
}
} While (
$id -match '^[0-9A-F]{8}$'
)
# Ask image url, can not empty
Do {
$url = Read-Host "Image URL"
} While (
!$url
)
# Ask image source, can not empty
Do {
$source = Read-Host "Image Source URL"
} While (
!$source
)
# Try autofill artist name and url by parsing $source if it is from twitter or deviantart
Switch -Regex ($source) {
"^https?://(www.|mobile.)?twitter.com" {
# assumes link is https://twitter.com/abakada/status/123456789012345, and the artist is abakada
$string = $source -replace "^https?://(www.|mobile.)?twitter.com/", ""
$string = $string -replace "/status/.*", ""
$artist = $string
$artistUrl = "https://twitter.com/$string"
}
"^https?://(www.)?deviantart.com" {
$string = $source -replace "^https?://(www.)?deviantart.com/", ""
$string = $string -replace "/art/[\w\-]+", ""
$artist = $string
$artistUrl = "https://www.deviantart.com/$artist"
}
"^https?://[\w]+.lofter.com" {
$string = $source -replace "^https?://", ""
$string = $string -replace "\.lofter.com/post/[\w_]+", ""
$artist = $string
$artistUrl = "https://$($string).lofter.com"
}
}
# Ask artist name, can not empty
Do {
if (!$artist) {
$artist = Read-Host "Artist Name"
}
else {
$art = $artist
$artist = Read-Host "Artist Name ($artist)"
if (!$artist) {$artist = $art}
}
} While (
!$artist
)
# Ask artist url, can not empty
Do {
if (!$artistUrl) {
$artistUrl = Read-Host "Artist URL"
}
else {
$aurl = $artistUrl
$artistUrl = Read-Host "Artist URL ($artistUrl)"
If (!$artistUrl) {$artistUrl = $aurl }
}
} While (
!$artistUrl
)
# Guess the platform
$platform = Switch -Regex ($source) {
"^https?://(www.)?pixiv.net" { "pixiv" }
"^https?://(mobile.|www.)?twitter.com" { "twitter" }
"^https?://(www.)?deviantart.com" { "deviantart" }
"^https?://(www.)?instagram.com" { "instagram" }
"^https?://(www.)?reddit.com" { "reddit" }
"^https?://[\w]+.lofter.com" { "lofter" }
"^https?://(www.)?tumblr.com" { "tumblr" }
"^https?://(www.)?weibo.com" { "weibo" }
"^https?://(www.)?patreon.com" { "patreon" }
"^https?://(www.)?artstation.com" { "artstation" }
"^https?://seiga.nicovideo.jp" { "seiga" }
"^https?://(www.)?reddit.com" { "reddit" }
"^https?://(www.)?hoyolab.com" { "hoyolab" }
default {
Read-Host "Unknown platform, please input manually"
}
}
Write-Host "Platform: $platform"
# Ask the media source, if empty put #N/A
$media = Read-Host "Media Source (#N/A)"
if (!$media) {
$media = "#N/A"
}
# Ask gender on the image, selection [b]oy/[g]irl/b[o]th/[f]luid
Do {
Write-Host "Gender on image"
Write-Host "- [b]oy" -ForegroundColor Blue
Write-Host "- [g]irl" -ForegroundColor Red
Write-Host "- b[o]th" -ForegroundColor Yellow
Write-Host "- [f]luid" -ForegroundColor Green
$gender = Read-Host "Selection"
} While (
$gender -notin @("b", "g", "o", "f", "boy", "girl", "both", "fluid")
)
$gender = Switch ($gender) {
"b" { "boy" }
"g" { "girl" }
"o" { "duo" }
"both" { "duo" }
"f" { "nb" }
"fluid" { "nb" }
}
# input all prompt to csv
$datainput = [PsCustomObject][ordered]@{
id = $id
imageUrl = $url
artist = $artist
artistUrl = $artistUrl
platform = $platform
imageSourceUrl = $source
mediaSource = $media
girlOrBoy = $gender
}
$csv += $datainput
# Sort column, then save
$csv | Select-Object id, imageUrl, artist, artistUrl, platform, imageSourceUrl, mediaSource, girlOrBoy | Export-Csv -Path index.tsv -Delimiter "`t" -NoTypeInformation -UseQuotes AsNeeded
.\readmeGenerator.ps1
git add index.tsv README.md
git commit -m "Add ``$id`` ($gender) by $artist"
git push
}