Skip to content
This repository has been archived by the owner on Jun 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #15 from Inazuma110/develop
Browse files Browse the repository at this point in the history
v0.0.1
  • Loading branch information
Inazuma110 committed Dec 8, 2018
2 parents a13adcd + 7cc692d commit 8a983d2
Show file tree
Hide file tree
Showing 28 changed files with 1,436 additions and 1,030 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -12,3 +12,9 @@ yarn-error.log*
*.ntvs*
*.njsproj
*.sln


src/api/data/battleHistory.json
src/api/data/form.json
src/api/data/headers.json
src/api/ss/*
1 change: 1 addition & 0 deletions .python-version
@@ -0,0 +1 @@
poke-rate-hub
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 Inazuma110

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
49 changes: 44 additions & 5 deletions README.md
@@ -1,21 +1,60 @@
# poke-rate-hub

## Overview
> Create Pokemon rating battle graph like GitHub!
## Usage
### Howto get savedataIdCode

1. Goto page [Pokemon Global Link](https://3ds.pokemon-gl.com/) and login.
1. savedataIdCode is A-326-2494-J<br>
![image](https://user-images.githubusercontent.com/31335755/49682267-e4a84f80-faf4-11e8-9696-5b5e028842e9.png)

## Warning
You have to publish rating battle.
### Howto publish rating battle.(Image is JP account)
1. Go to your profile(mypage).<br>
![image](https://user-images.githubusercontent.com/31335755/49682364-33a2b480-faf6-11e8-8e5f-6e17577216a5.png)
1. Click settings of public scope.<br>
![image](https://user-images.githubusercontent.com/31335755/49682374-6c428e00-faf6-11e8-8233-ab85986744a0.png)
1. Publish Rating battle.<br>
![image](https://user-images.githubusercontent.com/31335755/49682397-ba579180-faf6-11e8-95c7-80098c8c9569.png)

## Example SavedataIdCode
You can try PokeRateHub using these savedataIdCodes.
- A-326-2494-J (Ultra Sun)
- E-454-0005-X (Ultra Moon)
- J-599-9902-I (Ultra Sun)
- G-277-9551-T (Moon) (No battle history)


## demo
### SavedataIdCode: A-326-2494-J
![image](https://user-images.githubusercontent.com/31335755/49682220-24bb0280-faf4-11e8-85ca-1d1f248b4003.png)

## Next feature
Check Issues

## Contribute
Fork and send Pull Request.
I will welcome it!!

## Build Setup

``` bash
# install dependencies
npm install
yarn install

# serve with hot reload at localhost:8080
npm run dev
yarn run dev

# start api server
node src/api/server.js # in project root

# build for production with minification
npm run build
yarn run build

# build for production and view the bundle analyzer report
npm run build --report
yarn run build --report
```

For a detailed explanation on how things work, check out the [guide](http://vuejs-templates.github.io/webpack/) and [docs for vue-loader](http://vuejs.github.io/vue-loader).
1 change: 1 addition & 0 deletions build/webpack.dev.conf.js
Expand Up @@ -22,6 +22,7 @@ const devWebpackConfig = merge(baseWebpackConfig, {

// these devServer options should be customized in /config/index.js
devServer: {
// public: 'http://f9b74480.ngrok.io',
clientLogLevel: 'warning',
historyApiFallback: {
rewrites: [
Expand Down
5 changes: 3 additions & 2 deletions config/index.js
Expand Up @@ -10,7 +10,8 @@ module.exports = {
// Paths
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
proxyTable: {
},

// Various Dev Server settings
host: 'localhost', // can be overwritten by process.env.HOST
Expand All @@ -20,7 +21,7 @@ module.exports = {
notifyOnErrors: true,
poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-


/**
* Source Maps
*/
Expand Down
13 changes: 12 additions & 1 deletion index.html
Expand Up @@ -3,7 +3,18 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>poke-rate-hub</title>
<script src="https://d3js.org/d3.v3.min.js" charset="utf-8">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.12.0/moment.min.js">
</script>
<meta property="og:url" content="http://localhost:8080/" />
<meta property="og:title" content="PokeRateHub" />
<meta property="og:description" content="Create Pokemon Rating battle in this 365 days graph" />
<meta property="og:image" content="" />
<meta name="twitter:card" content="summary_large_image"/>
<!-- <link rel="shortcut icon" href="favicon.ico" type="image/vnd.microsoft.icon"> -->
<title>PokeRateHub</title>

</head>
<body>
<div id="app"></div>
Expand Down
8 changes: 7 additions & 1 deletion package.json
Expand Up @@ -10,6 +10,9 @@
"build": "node build/build.js"
},
"dependencies": {
"axios": "^0.18.0",
"cors": "^2.8.5",
"puppeteer": "^1.11.0",
"vue": "^2.5.2",
"vue-router": "^3.0.1"
},
Expand All @@ -23,9 +26,10 @@
"babel-plugin-transform-vue-jsx": "^3.5.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"chalk": "^2.0.1",
"bootstrap-vue": "^2.0.0-rc.11",
"copy-webpack-plugin": "^4.0.1",
"css-loader": "^0.28.0",
"express": "^4.16.4",
"extract-text-webpack-plugin": "^3.0.0",
"file-loader": "^1.1.4",
"friendly-errors-webpack-plugin": "^1.6.1",
Expand All @@ -37,6 +41,8 @@
"postcss-import": "^11.0.0",
"postcss-loader": "^2.0.8",
"postcss-url": "^7.2.1",
"request": "^2.88.0",
"request-promise": "^4.2.2",
"rimraf": "^2.6.0",
"semver": "^5.3.0",
"shelljs": "^0.7.6",
Expand Down
15 changes: 12 additions & 3 deletions src/App.vue
@@ -1,13 +1,22 @@
<template>
<div id="app">
<img src="./assets/logo.png">
<Header/>
<!-- <img src="./assets/logo.png"> -->
<router-view/>
<Footer/>
</div>
</template>

<script>
import Header from '@/components/Header';
import Footer from '@/components/Footer';
export default {
name: 'App'
name: 'App',
components: {
Header,
Footer,
},
}
</script>

Expand All @@ -18,6 +27,6 @@ export default {
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
margin-top: 0px;
}
</style>
13 changes: 13 additions & 0 deletions src/api/data/headersTemplate.json
@@ -0,0 +1,13 @@
{
"Host": "3ds.pokemon-gl.com",
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0",
"Accept": "*/*",
"Accept-Language": "ja,en-US;q=0.7,en;q=0.3",
"Accept-Encoding": "gzip, deflate, br",
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"X-Requested-With": "XMLHttpRequest",
"Referer": "",
"Content-Length": "159",
"Cookie": "region=0; language_id=1; site=1; JSESSIONID=8B716AD73AE9616941C50AC0DEAE8310; AWSELB=C95303410E583113FAF27D987FE57908F5BE8EE44BA8A0AD236B0D591F44F929CEDC6D81BBD1D19066C332A55EB39B7CE28E1F48F8415CBDE6FB8D2992031AF6D756E47174BEE8896177D6EA2DF4EDD6B9A4A42C42; _ga=GA1.2.1594122966.1541393827; _gid=GA1.2.1641740835.1541393827; NO_MEMBER_DATA=%7B%22language_id%22%3A1%2C%22site%22%3A1%2C%22region%22%3A0%7D; __ulfpc=201811051357063269; s_fid=10191B9F70C14FDA-0882A920BCB619D0; s_cc=true; s_sq=%5B%5BB%5D%5D; _gat=1",
"Connection": "keep-alive"
}
7 changes: 7 additions & 0 deletions src/api/data/payloadTemplate.json
@@ -0,0 +1,7 @@
{
"languageId":1,
"accountId":"",
"savedataId":"",
"battleType":"",
"count":10000
}
21 changes: 21 additions & 0 deletions src/api/getBattleHistory.py
@@ -0,0 +1,21 @@
import requests
from time import sleep
import json
import sys

dataFilePath = './src/api/data/';
url = "https://3ds.pokemon-gl.com/frontendApi/mypage/getGbuBattleList"

with open(f'{dataFilePath}headers.json', 'r') as f:
headers = json.load(f)

with open(f'{dataFilePath}form.json', 'r') as f:
payload = json.load(f)

r = requests.post(url, headers=headers, data=payload)
j = r.json()

with open(f'{dataFilePath}battleHistory.json', 'w') as f:
f.write(json.dumps(j, indent=2))

# print(json.dumps(j, indent=2))
129 changes: 129 additions & 0 deletions src/api/server.js
@@ -0,0 +1,129 @@
const express = require('express');
const app = express();

const fs = require('fs');
const exec = require('child_process').exec;
const req = require('request-promise');
// const puppeteer = require('puppeteer');

const dataFilePath = './src/api/data/';

let accountId, savedataId;

const getValue = async(savedataIdCode) => {
const url = `https://3ds.pokemon-gl.com/user/${savedataIdCode}/profile/`;
const opt = {
url: url,
json: true,
}

let body = await req.get (opt, (e, res, b) => {
return b;
});

const accountIdRe = /USERS_ACCOUNT_ID='(.*?)'/g;
accountId = body.match(accountIdRe)[0];
accountId = accountId.replace(accountIdRe, '$1');

const savedataIdRe = /USERS_SAVEDATA_ID='(.*?)'/g;
savedataId = body.match(savedataIdRe)[0];
savedataId = savedataId.replace(savedataIdRe, '$1');
}

const getBattleHistory = async(savedataIdCode) => {
const url = "https://3ds.pokemon-gl.com/frontendApi/mypage/getGbuBattleList";
const referer = `https://3ds.pokemon-gl.com/user/${savedataIdCode}/battle/`;

let headers =
JSON.parse(fs.readFileSync(`${dataFilePath}headersTemplate.json`, 'utf-8'));
headers['Referer'] = referer;

let form =
JSON.parse(fs.readFileSync(`${dataFilePath}payloadTemplate.json`, 'utf-8'));
form['accountId'] = accountId;
form['savedataId'] = savedataId;

const arg1 = JSON.stringify(headers);
const arg2 = JSON.stringify(form);


fs.writeFileSync(`${dataFilePath}headers.json`, arg1);
fs.writeFileSync(`${dataFilePath}form.json`, arg2);

const res = exec('python3 ./src/api/getBattleHistory.py',
(err, sout, serr) => {
console.log(sout);
console.log(serr);
});
}

const ss = async(savedataIdCode, ssPath) => {
const puppeteer = require('puppeteer');
const browser = await puppeteer.launch({
args: [
'--no-sandbox',
'--disable-setuid-sandbox'
],
// headless: false,
});
const page = await browser.newPage();
await page.setViewport({ width: 1020, height: 980 })
await page.goto('localhost:8080');
await page.type('#savedateidcode', savedataIdCode);
await page.click('#create');

await page.waitFor('#poke');

const clip = await page.evaluate(s => {
const el = document.querySelector(s)

const { width, height, top: y, left: x } = el.getBoundingClientRect()
return { width, height, x, y }
}, '#poke')

let element = await page.$('#poke');
await page.screenshot({clip, path: ssPath});

browser.close();
}

const cors = require('cors');
app.use(cors());

// http://localhost:3000/api/v1/battleHistory
app.get('/api/v1/battleHistory', async(req, res) => {
const savedataIdCode = await req.query.savedataIdCode;

console.log(`GET Request: ${savedataIdCode}`);


try{
await getValue(savedataIdCode);
await getBattleHistory(savedataIdCode);
}catch(err){
await res.json({'statusCode': '4444'});
return;
}

const battleHistory =
await JSON.parse(fs.readFileSync(`${dataFilePath}battleHistory.json`));


await res.json(battleHistory);
});

// http://localhost:3000/api/v1/ss
app.get('/api/v1/ss', async(req, res) => {
const savedataIdCode = await req.query.savedataIdCode;
const ssPath = `./src/api/ss/${savedataIdCode}.png`

console.log(`GET SS Request: ${savedataIdCode}`);
console.log();

ss(savedataIdCode, ssPath);
await res.json({'path': ssPath});

})


app.listen(3000, () => console.log('Listening on port 3000'));
Binary file added src/assets/GitHub-Mark-32px.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/Twitter_Logo_Blue.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/assets/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8a983d2

Please sign in to comment.