Skip to content

Commit ab13777

Browse files
committed
working on pulling multiple files together
1 parent 795c030 commit ab13777

File tree

4 files changed

+129
-64
lines changed

4 files changed

+129
-64
lines changed

_dev/pull_dev.go

-47
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@ package main
22

33
import (
44
"encoding/base64"
5-
"io/ioutil"
6-
"log"
7-
"os"
85
// "reflect"
96

10-
"github.com/Jeffail/gabs"
117
"gopkg.in/resty.v1"
128
)
139

@@ -36,47 +32,4 @@ func saveResponseAndConvert() {
3632
if err != nil {
3733
panic(err)
3834
}
39-
40-
//fmt.Println(resp)
41-
42-
resJson, _ := gabs.ParseJSON([]byte(resp.String()))
43-
children, _ := resJson.S("file_content").Children()
44-
child := children[0]
45-
46-
//TODO: Iterate this over all the file names recieved from the remote
47-
file, err := os.Create("temp.txt")
48-
if err != nil {
49-
log.Fatal("Cannot create file", err)
50-
}
51-
defer file.Close()
52-
53-
_, err = file.WriteString(child.String())
54-
55-
// This works perfectly
56-
//fmt.Println("Decoding the string manually")
57-
//x := "PCEtLSBUcmFuc2xhdGVkIEJ5IERldm5hZ3JpIC0tPgo8IS0tIGh0dHA6Ly9kZXZuYWdyaS5jb20gLS0+CjxyZXNvdXJjZXMgdG9vbHM6aWdub3JlPSJFeHRyYVRyYW5zbGF0aW9uIiB4bWxuczp0b29scz0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vdG9vbHMiPgogICAgPHN0cmluZyBuYW1lPSJhcHBfbmFtZSI+PC9zdHJpbmc+CiAgICA8c3RyaW5nIG5hbWU9ImhpbnRfYWN0dWFsIj48L3N0cmluZz4KIDwvcmVzb3VyY2VzPg=="
58-
//decodeBase64(x)
59-
60-
dat, _ := ioutil.ReadFile("temp.txt")
61-
datString := string(dat)
62-
//fmt.Println("String Length : ", len(datString))
63-
content := datString[1:(len(datString) - 1)]
64-
//fmt.Println(content)
65-
fileContent := decodeBase64(content)
66-
//fmt.Println(fileContent)
67-
//fmt.Println("<<< Reading temp file now >>>")
68-
//fileContent := decodeBase64(string(dat))
69-
//fmt.Println(fileContent)
70-
71-
//TODO: Store the content of temp into the actual file
72-
responseFile, err := os.Create("responseFile.txt")
73-
if err != nil {
74-
log.Fatal("Cannot create file", err)
75-
}
76-
defer responseFile.Close()
77-
78-
_, err = responseFile.WriteString(fileContent)
79-
80-
//TODO: Delete the temp file
81-
8235
}

_dev/pull_multiple.go

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package main
2+
3+
import (
4+
"encoding/base64"
5+
"fmt"
6+
// "io/ioutil"
7+
"log"
8+
"os"
9+
// "reflect"
10+
11+
"github.com/FourtekIT/devnagri-cli/config"
12+
"github.com/Jeffail/gabs"
13+
"github.com/spf13/viper"
14+
"gopkg.in/resty.v1"
15+
)
16+
17+
func main() {
18+
saveResponseAndConvert()
19+
}
20+
21+
func decodeBase64(cypher string) string {
22+
23+
data, _ := base64.StdEncoding.DecodeString(cypher)
24+
25+
return string(data)
26+
27+
}
28+
29+
func saveResponseAndConvert() {
30+
31+
var ClientID = config.FetchAndValidate("ClientID") // returns string
32+
33+
var ClientSecret = config.FetchAndValidate("ClientSecret") // returns string
34+
35+
var ProjectKey = config.FetchAndValidate("ProjectKey") // returns string
36+
37+
var AccessToken = config.FetchAndValidate("AccessToken") // returns string
38+
39+
resp, err := resty.R().
40+
SetHeader("Accept", "application/json").
41+
SetHeader("Content-Type", "multipart/form-data").
42+
SetAuthToken(AccessToken).
43+
SetFormData(map[string]string{
44+
"client_id": ClientID,
45+
"client_secret": ClientSecret,
46+
"project_key": ProjectKey}).
47+
Post("http://dev.devnagri.co.in/api/project/pull")
48+
49+
if err != nil {
50+
panic(err)
51+
}
52+
53+
//fmt.Println(resp)
54+
resJson, _ := gabs.ParseJSON([]byte(resp.String()))
55+
56+
fmt.Println(resJson)
57+
children, _ := resJson.S("file_content").Children()
58+
child := children[0]
59+
//fmt.Println(child.String())
60+
61+
//TODO: Iterate this over all the file names recieved from the remote
62+
file, err := os.Create("temp.txt")
63+
if err != nil {
64+
log.Fatal("Cannot create file", err)
65+
}
66+
defer file.Close()
67+
68+
_, err = file.WriteString(child.String())
69+
70+
// This works perfectly
71+
//fmt.Println("Decoding the string manually")
72+
//x := "PCEtLSBUcmFuc2xhdGVkIEJ5IERldm5hZ3JpIC0tPgo8IS0tIGh0dHA6Ly9kZXZuYWdyaS5jb20gLS0+CjxyZXNvdXJjZXMgdG9vbHM6aWdub3JlPSJFeHRyYVRyYW5zbGF0aW9uIiB4bWxuczp0b29scz0iaHR0cDovL3NjaGVtYXMuYW5kcm9pZC5jb20vdG9vbHMiPgogICAgPHN0cmluZyBuYW1lPSJhcHBfbmFtZSI+PC9zdHJpbmc+CiAgICA8c3RyaW5nIG5hbWU9ImhpbnRfYWN0dWFsIj48L3N0cmluZz4KIDwvcmVzb3VyY2VzPg=="
73+
//decodeBase64(x)
74+
75+
//dat, _ := ioutil.ReadFile("temp.txt")
76+
//datString := string(dat)
77+
//fmt.Println("String Length : ", len(datString))
78+
79+
//content := datString[1:(len(datString) - 1)]
80+
//fmt.Println(content)
81+
82+
//fileContent := decodeBase64(content)
83+
//fmt.Println(fileContent)
84+
85+
//fmt.Println("<<< Reading temp file now >>>")
86+
//fileContent := decodeBase64(string(dat))
87+
//fmt.Println(fileContent)
88+
89+
//TODO: This should be abstracted to various languages
90+
91+
//TODO: Read all the languages mentioned in the YAML file
92+
93+
fieldValue := viper.GetStringSlice("TargetLanguages") // returns string
94+
fmt.Println(fieldValue)
95+
96+
/*
97+
//TODO: Make the << hi >> dir
98+
if _, err := os.Stat("./values-hi"); os.IsNotExist(err) {
99+
os.Mkdir("./values-hi", os.ModePerm)
100+
}
101+
102+
//TODO: Store the content of temp into the actual file
103+
104+
responseFile, err := os.Create("./values-hi/strings.xml")
105+
106+
if err != nil {
107+
log.Fatal("Cannot create file", err)
108+
}
109+
defer responseFile.Close()
110+
111+
_, err = responseFile.WriteString(fileContent)
112+
113+
os.Remove("temp.txt")
114+
115+
*/
116+
fmt.Println("Done!")
117+
118+
}

_dev/responseFile.txt

-6
This file was deleted.

utils/langCodes.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package utils
22

3-
var LangCodes = map[string]string {
4-
"English" : "en",
5-
"Hindi" : "hi",
6-
"Punjabi" : "pa",
7-
"Tamil" : "ta",
8-
"Gujarati" : "gu",
9-
"Kannada" : "kn",
10-
"Bengali" : "bn",
11-
"Marathi" : "mr",
12-
"Telugu" : "te"
13-
}
3+
var LangCodes = map[string]string{
4+
"English": "en",
5+
"Hindi": "hi",
6+
"Punjabi": "pa",
7+
"Tamil": "ta",
8+
"Gujarati": "gu",
9+
"Kannada": "kn",
10+
"Bengali": "bn",
11+
"Marathi": "mr",
12+
"Telugu": "te",
13+
}

0 commit comments

Comments
 (0)