<commit_before>package pushManager

import (
	"Go_Baidu_Push/config"
	"Go_Baidu_Push/util"
	"bytes"
	"encoding/json"
	"errors"
	"io/ioutil"
	"log"
	"net/http"
	"net/url"

	"strconv"
	"time"
)

var _pm *PushManager

func SharedPushManager() *PushManager {
	if _pm == nil {
		_pm = &PushManager{
			secretKey: config.SECRET_KEY,
			apiKey:    config.API_KEY,
		}
	}
	return _pm
}

type PushManager struct {
	secretKey string
	apiKey    string
}

func (p *PushManager) applyBaseParameters(parameters map[string]string) {
	parameters["apikey"] = p.apiKey
	parameters["timestamp"] = strconv.FormatInt(time.Now().Unix(), 10)
}

func (p *PushManager) PushToAll(device_type, msg_type, msg, deploy_status string, parameters map[string]string) (resp map[string]interface{}, err error) {
	targetURL := "http://api.tuisong.baidu.com/rest/3.0/push/all"
	dic := make(map[string]string)
	dic["device_type"] = device_type
	dic["msg_type"] = msg_type
	dic["deploy_status"] = deploy_status
	dic["msg"] = util.BuildMessage(msg, parameters, device_type)
	p.applyBaseParameters(dic)
	dic["sign"] = util.GenerateSignature("POST", targetURL, p.secretKey, dic)
	return postURL(targetURL, dic)
}

func (p *PushManager) PushToSingle(device_type, channel_id, msg_type, msg, deploy_status string, parameters map[string]string) (resp map[string]interface{}, err error) {
	targetURL := "http://api.tuisong.baidu.com/rest/3.0/push/single_device"
	dic := make(map[string]string)
	dic["device_type"] = device_type
	dic["msg_type"] = msg_type
	dic["deploy_status"] = deploy_status
	dic["channel_id"] = channel_id
	dic["msg"] = util.BuildMessage(msg, parameters, device_type)
	p.applyBaseParameters(dic)
	dic["sign"] = util.GenerateSignature("POST", targetURL, p.secretKey, dic)
	return postURL(targetURL, dic)
}

func (p *PushManager) PushToTag(device_type, tag, msg_type, msg, deploy_status string, parameters map[string]string) (resp map[string]interface{}, err error) {
	targetURL := "http://api.tuisong.baidu.com/rest/3.0/push/tags"
	dic := make(map[string]string)
	dic["type"] = "1"
	dic["device_type"] = device_type
	dic["tag"] = tag
	dic["msg_type"] = msg_type
	dic["deploy_status"] = deploy_status
	dic["msg"] = util.BuildMessage(msg, parameters, device_type)
	p.applyBaseParameters(dic)
	dic["sign"] = util.GenerateSignature("POST", targetURL, p.secretKey, dic)
	return postURL(targetURL, dic)
}

func (p *PushManager) PushToBatchDevices(device_type, msg_type, msg, topicId string, channel_ids []string, parameters map[string]string) (resp map[string]interface{}, err error) {
	targetURL := "http://api.tuisong.baidu.com/rest/3.0/push/batch_device"
	dic := make(map[string]string)
	channels, err := json.Marshal(&channel_ids)
	if err != nil {
		return
	}
	dic["channel_ids"] = string(channels)
	dic["device_type"] = device_type
	dic["msg_type"] = msg_type
	dic["msg"] = util.BuildMessage(msg, parameters, device_type)
	p.applyBaseParameters(dic)
	dic["sign"] = util.GenerateSignature("POST", targetURL, p.secretKey, dic)
	return postURL(targetURL, dic)
}

func (p *PushManager) QueryMsgStatus(msgIds []string) (resp map[string]interface{}, err error) {
	targetURL := "http://api.tuisong.baidu.com/rest/3.0/report/query_msg_status"
	dic := make(map[string]string)
	ids, err := json.Marshal(&msgIds)
	if err != nil {
		return
	}
	dic["msg_id"] = string(ids)
	p.applyBaseParameters(dic)
	dic["sign"] = util.GenerateSignature("POST", targetURL, p.secretKey, dic)
	return postURL(targetURL, dic)
}

func (p *PushManager) QueryTimerRecords(timerId, start, limit, rangeStart, rangeEnd string) {

}

func (p *PushManager) QueryTopicRecords(topicId, start, limit, rangeStart, rangeEnd string) {

}

func (p *PushManager) QueryTagDetails(tag string) {

}
<commit_msg>Query timer tasks<commit_after>package pushManager

import (
	"Go_Baidu_Push/config"
	"Go_Baidu_Push/util"
	"bytes"
	"encoding/json"
	"errors"
	"io/ioutil"
	"log"
	"net/http"
	"net/url"

	"strconv"
	"time"
)

var _pm *PushManager

func SharedPushManager() *PushManager {
	if _pm == nil {
		_pm = &PushManager{
			secretKey: config.SECRET_KEY,
			apiKey:    config.API_KEY,
		}
	}
	return _pm
}

type PushManager struct {
	secretKey string
	apiKey    string
}

func (p *PushManager) applyBaseParameters(parameters map[string]string) {
	parameters["apikey"] = p.apiKey
	parameters["timestamp"] = strconv.FormatInt(time.Now().Unix(), 10)
}

func (p *PushManager) PushToAll(device_type, msg_type, msg, deploy_status string, parameters map[string]string) (resp map[string]interface{}, err error) {
	targetURL := "http://api.tuisong.baidu.com/rest/3.0/push/all"
	dic := make(map[string]string)
	dic["device_type"] = device_type
	dic["msg_type"] = msg_type
	dic["deploy_status"] = deploy_status
	dic["msg"] = util.BuildMessage(msg, parameters, device_type)
	p.applyBaseParameters(dic)
	dic["sign"] = util.GenerateSignature("POST", targetURL, p.secretKey, dic)
	return postURL(targetURL, dic)
}

func (p *PushManager) PushToSingle(device_type, channel_id, msg_type, msg, deploy_status string, parameters map[string]string) (resp map[string]interface{}, err error) {
	targetURL := "http://api.tuisong.baidu.com/rest/3.0/push/single_device"
	dic := make(map[string]string)
	dic["device_type"] = device_type
	dic["msg_type"] = msg_type
	dic["deploy_status"] = deploy_status
	dic["channel_id"] = channel_id
	dic["msg"] = util.BuildMessage(msg, parameters, device_type)
	p.applyBaseParameters(dic)
	dic["sign"] = util.GenerateSignature("POST", targetURL, p.secretKey, dic)
	return postURL(targetURL, dic)
}

func (p *PushManager) PushToTag(device_type, tag, msg_type, msg, deploy_status string, parameters map[string]string) (resp map[string]interface{}, err error) {
	targetURL := "http://api.tuisong.baidu.com/rest/3.0/push/tags"
	dic := make(map[string]string)
	dic["type"] = "1"
	dic["device_type"] = device_type
	dic["tag"] = tag
	dic["msg_type"] = msg_type
	dic["deploy_status"] = deploy_status
	dic["msg"] = util.BuildMessage(msg, parameters, device_type)
	p.applyBaseParameters(dic)
	dic["sign"] = util.GenerateSignature("POST", targetURL, p.secretKey, dic)
	return postURL(targetURL, dic)
}

func (p *PushManager) PushToBatchDevices(device_type, msg_type, msg, topicId string, channel_ids []string, parameters map[string]string) (resp map[string]interface{}, err error) {
	targetURL := "http://api.tuisong.baidu.com/rest/3.0/push/batch_device"
	dic := make(map[string]string)
	channels, err := json.Marshal(&channel_ids)
	if err != nil {
		return
	}
	dic["channel_ids"] = string(channels)
	dic["device_type"] = device_type
	dic["msg_type"] = msg_type
	dic["msg"] = util.BuildMessage(msg, parameters, device_type)
	p.applyBaseParameters(dic)
	dic["sign"] = util.GenerateSignature("POST", targetURL, p.secretKey, dic)
	return postURL(targetURL, dic)
}

func (p *PushManager) QueryMsgStatus(msgIds []string) (resp map[string]interface{}, err error) {
	targetURL := "http://api.tuisong.baidu.com/rest/3.0/report/query_msg_status"
	dic := make(map[string]string)
	ids, err := json.Marshal(&msgIds)
	if err != nil {
		return
	}
	dic["msg_id"] = string(ids)
	p.applyBaseParameters(dic)
	dic["sign"] = util.GenerateSignature("POST", targetURL, p.secretKey, dic)
	return postURL(targetURL, dic)
}

func (p *PushManager) QueryTimerRecords(timerId, start, limit, rangeStart, rangeEnd string) (resp map[string]interface{}, err error) {
	targetURL := "http://api.tuisong.baidu.com/rest/3.0/report/query_timer_records"
	dic := make(map[string]string)
	dic["timer_id"] = timerId
	if start != "" {
		dic["start"] = start
	}
	if limit != "" {
		dic["limit"] = limit
	}
	if rangeStart != "" {
		dic["rangeStart"] = rangeStart
	}
	if rangeEnd != "" {
		dic["rangeEnd"] = rangeEnd
	}

	p.applyBaseParameters(dic)
	dic["sign"] = util.GenerateSignature("POST", targetURL, p.secretKey, dic)
	return postURL(targetURL, dic)
}

func (p *PushManager) QueryTopicRecords(topicId, start, limit, rangeStart, rangeEnd string) {

}

func (p *PushManager) QueryTagDetails(tag string) {

}

{'fraction_non_alphanumeric': 0.15443386773547094, 'fraction_numerical': 0.0035070140280561123, 'mean_word_length': 5.901469317199655, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1522620', 'n_tokens_mistral': 2992, 'n_tokens_neox': 2946, 'n_words': 571}