implement vuex et authent #2
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
|||||||
__*
|
__pycache__
|
||||||
env
|
env
|
||||||
venv
|
venv
|
||||||
dist
|
dist
|
0
backend/__init__.py
Normal file
0
backend/__init__.py
Normal file
0
backend/chainetv/__init__.py
Normal file
0
backend/chainetv/__init__.py
Normal file
34
backend/chainetv/api.py
Normal file
34
backend/chainetv/api.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
from flask import Blueprint, jsonify, request,make_response,redirect,url_for,render_template
|
||||||
|
from chainetv.Jsonfile import JSONfile
|
||||||
|
from chainetv import emission
|
||||||
|
data= JSONfile("chaine.json")
|
||||||
|
|
||||||
|
|
||||||
|
api = Blueprint("api", __name__)
|
||||||
|
@api.route('/ping', methods=['GET'])
|
||||||
|
def ping_pong():
|
||||||
|
return jsonify('pong!')
|
||||||
|
|
||||||
|
@api.route('/chaine/<num>', methods=['GET'])
|
||||||
|
def get_chaine(num):
|
||||||
|
chaine=data.get_chaine(num)
|
||||||
|
if (chaine == "numero de chaine inconnue"):
|
||||||
|
return make_response("",204)
|
||||||
|
else:
|
||||||
|
return jsonify(chaine)
|
||||||
|
|
||||||
|
@api.route('/chaine/', methods=['put'])
|
||||||
|
def update_list():
|
||||||
|
status=data.parsechaine()
|
||||||
|
if(status=='ok'):
|
||||||
|
return jsonify("OK")
|
||||||
|
else:
|
||||||
|
return make_response('Error during Chaine Update',500)
|
||||||
|
|
||||||
|
@api.route('/chaine/<num>/emission', methods=['GET'])
|
||||||
|
def get_emmission(num):
|
||||||
|
chaine=data.get_chaine(num)
|
||||||
|
if (chaine == "numero de chaine inconnue"):
|
||||||
|
return make_response("",204)
|
||||||
|
else:
|
||||||
|
return jsonify(emission.parse_emmission(chaine))
|
21
backend/chainetv/app.py
Normal file
21
backend/chainetv/app.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
from flask import Flask,render_template
|
||||||
|
from flask_cors import CORS
|
||||||
|
|
||||||
|
#from ReverseProxied import ReverseProxied
|
||||||
|
def create_app(app_name=__name__):
|
||||||
|
app=Flask(__name__, static_folder= "../dist/static",template_folder="../dist")
|
||||||
|
app.config.from_object('chainetv.config.BaseConfig')
|
||||||
|
#app.wsgi_app = ReverseProxied(app.wsgi_app)
|
||||||
|
CORS(app)
|
||||||
|
from chainetv.api import api
|
||||||
|
app.register_blueprint(api, url_prefix="/api/v1")
|
||||||
|
@app.route('/')
|
||||||
|
@app.route('/<path:path>')
|
||||||
|
def index(path="/"):
|
||||||
|
return render_template('index.html')
|
||||||
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
##@app.errorhandler(404)
|
||||||
|
##def ma_page_404(error):
|
||||||
|
## return redirect("https://www.ducamps.win/404/404.html", 307)
|
3
backend/chainetv/config.py
Normal file
3
backend/chainetv/config.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
class BaseConfig(object):
|
||||||
|
DEBUG = True
|
||||||
|
SECRET_KEY = 'mysecretkeyg'
|
@ -24,14 +24,22 @@ def parse_emmission(strsearch):
|
|||||||
html = response.read()
|
html = response.read()
|
||||||
parse=BeautifulSoup(html,"html.parser")
|
parse=BeautifulSoup(html,"html.parser")
|
||||||
divcasting=parse.select_one(".descriptif")
|
divcasting=parse.select_one(".descriptif")
|
||||||
|
if (divcasting):
|
||||||
casting=divcasting.find_all(href=re.compile("biographie"))
|
casting=divcasting.find_all(href=re.compile("biographie"))
|
||||||
count=0
|
count=0
|
||||||
for actor in casting:
|
for actor in casting:
|
||||||
casting[count]=actor.text
|
casting[count]=actor.text
|
||||||
count+=1
|
count+=1
|
||||||
|
else:
|
||||||
|
casting= None
|
||||||
divsynopsis=parse.select_one(".episode-synopsis")
|
divsynopsis=parse.select_one(".episode-synopsis")
|
||||||
|
if (divsynopsis):
|
||||||
img=divsynopsis.find_next('img')['data-src']
|
img=divsynopsis.find_next('img')['data-src']
|
||||||
synopsis=divsynopsis.select_one(".d-b").text
|
synopsis=divsynopsis.select_one(".d-b").text
|
||||||
|
else:
|
||||||
|
img=None
|
||||||
|
synopsis=""
|
||||||
|
|
||||||
return {'title':link['title'],'href':href,'casting':casting,'synopsis':remove_first_space(synopsis),'img':img}
|
return {'title':link['title'],'href':href,'casting':casting,'synopsis':remove_first_space(synopsis),'img':img}
|
||||||
|
|
||||||
|
|
@ -1,52 +1,5 @@
|
|||||||
from flask import Flask,request,make_response,redirect,url_for,render_template,jsonify
|
|
||||||
from flask_cors import CORS
|
|
||||||
from Jsonfile import JSONfile
|
|
||||||
#from ReverseProxied import ReverseProxied
|
|
||||||
import emission
|
|
||||||
data= JSONfile("chaine.json")
|
|
||||||
app=Flask(__name__,static_folder = "./dist/static",template_folder="./dist")
|
|
||||||
#app.wsgi_app = ReverseProxied(app.wsgi_app)
|
|
||||||
CORS(app)
|
|
||||||
|
|
||||||
@app.route('/', defaults={'path': ''})
|
|
||||||
@app.route('/<path:path>')
|
|
||||||
def index(path):
|
|
||||||
return render_template('index.html')
|
|
||||||
|
|
||||||
@app.route('/api/v1/ping', methods=['GET'])
|
|
||||||
def ping_pong():
|
|
||||||
return jsonify('pong!')
|
|
||||||
|
|
||||||
@app.route('/api/v1/chaine/<num>', methods=['GET'])
|
|
||||||
def get_chaine(num):
|
|
||||||
chaine=data.get_chaine(num)
|
|
||||||
if (chaine == "numero de chaine inconnue"):
|
|
||||||
return make_response("",204)
|
|
||||||
else:
|
|
||||||
return jsonify(chaine)
|
|
||||||
|
|
||||||
@app.route('/api/v1/chaine/', methods=['put'])
|
|
||||||
def update_list():
|
|
||||||
status=data.parsechaine()
|
|
||||||
if(status=='ok'):
|
|
||||||
return jsonify("OK")
|
|
||||||
else:
|
|
||||||
return make_response('Error during Chaine Update',500)
|
|
||||||
|
|
||||||
@app.route('/api/v1/chaine/<num>/emission', methods=['GET'])
|
|
||||||
def get_emmission(num):
|
|
||||||
chaine=data.get_chaine(num)
|
|
||||||
if (chaine == "numero de chaine inconnue"):
|
|
||||||
return make_response("",204)
|
|
||||||
else:
|
|
||||||
return jsonify(emission.parse_emmission(chaine))
|
|
||||||
|
|
||||||
##@app.errorhandler(404)
|
|
||||||
##def ma_page_404(error):
|
|
||||||
## return redirect("https://www.ducamps.win/404/404.html", 307)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
from chainetv.app import create_app
|
||||||
|
app= create_app()
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
app.run()
|
5
client/package-lock.json
generated
5
client/package-lock.json
generated
@ -11773,6 +11773,11 @@
|
|||||||
"integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==",
|
"integrity": "sha512-4gDntzrifFnCEvyoO8PqyJDmguXgVPxKiIxrBKjIowvL9l+N66196+72XVYR8BBf1Uv1Fgt3bGevJ+sEmxfZzw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"vuex": {
|
||||||
|
"version": "3.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/vuex/-/vuex-3.1.0.tgz",
|
||||||
|
"integrity": "sha512-mdHeHT/7u4BncpUZMlxNaIdcN/HIt1GsGG5LKByArvYG/v6DvHcOxvDCts+7SRdCoIRGllK8IMZvQtQXLppDYg=="
|
||||||
|
},
|
||||||
"watchpack": {
|
"watchpack": {
|
||||||
"version": "1.6.0",
|
"version": "1.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/watchpack/-/watchpack-1.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/watchpack/-/watchpack-1.6.0.tgz",
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
"axios": "^0.18.0",
|
"axios": "^0.18.0",
|
||||||
"bulma": "^0.7.4",
|
"bulma": "^0.7.4",
|
||||||
"vue": "^2.5.2",
|
"vue": "^2.5.2",
|
||||||
"vue-router": "^3.0.1"
|
"vue-router": "^3.0.1",
|
||||||
|
"vuex": "^3.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"autoprefixer": "^7.1.2",
|
"autoprefixer": "^7.1.2",
|
||||||
|
20
client/src/api/index.js
Normal file
20
client/src/api/index.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
const API_PATH=`${process.env.ROOT_API}/api/v1`;
|
||||||
|
|
||||||
|
export function fetchchaine(num){
|
||||||
|
|
||||||
|
return axios.get(`${API_PATH}/chaine/${num}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function fetchemission(num){
|
||||||
|
|
||||||
|
return axios.get(`${API_PATH}/chaine/${num}/emission`)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export function putparsechaine(){
|
||||||
|
|
||||||
|
return axios.put(`${API_PATH}/chaine/`);
|
||||||
|
|
||||||
|
}
|
@ -29,8 +29,8 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="section">
|
<div class="section">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<ul class v-if="arrayresultchaines">
|
<ul class v-if="this.$store.state.arrayresultchaines">
|
||||||
<li class="box" v-for="result in arrayresultchaines" v-bind:key="result.chaine">
|
<li class="box" v-for="result in this.$store.state.arrayresultchaines" v-bind:key="result.chaine">
|
||||||
<h3 class="title is-5">{{result.chaine}} : {{result.name}}</h3>
|
<h3 class="title is-5">{{result.chaine}} : {{result.name}}</h3>
|
||||||
<ul v-if="(result.emission!='can\'t find channel' && result.emission)">
|
<ul v-if="(result.emission!='can\'t find channel' && result.emission)">
|
||||||
<li>
|
<li>
|
||||||
@ -74,63 +74,34 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import axios from "axios";
|
import {putparsechaine} from "../api";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "chainetv",
|
name: "chainetv",
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
arrayresultchaines: [],
|
|
||||||
chaine: ""
|
chaine: ""
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getchaine(num) {
|
|
||||||
let path = process.env.ROOT_API + "/api/v1/chaine/";
|
|
||||||
axios
|
|
||||||
.get(path + num)
|
|
||||||
.then(res => {
|
|
||||||
if (res.status === 200) {
|
|
||||||
axios
|
|
||||||
.get(path + num + "/emission")
|
|
||||||
.then(res_emission => {
|
|
||||||
this.arrayresultchaines.push({
|
|
||||||
chaine: num,
|
|
||||||
name: res.data,
|
|
||||||
emission: res_emission.data
|
|
||||||
});
|
|
||||||
console.log(this.arrayresultchaines);
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
this.arrayresultchaines.push({ chaine: num, name: res.data });
|
|
||||||
});
|
|
||||||
} else if (res.status === 204) {
|
|
||||||
this.arrayresultchaines.push({ chaine: num, name: "inconnue" });
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
// eslint-disable-next-line
|
|
||||||
console.error(error);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
checkchaine() {
|
checkchaine() {
|
||||||
if (this.chaine === "") {
|
if (this.chaine === "") {
|
||||||
alert("rentrer un numéro");
|
alert("rentrer un numéro");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.arrayresultchaines = [];
|
this.$store.state.arrayresultchaines = [];
|
||||||
const arraychaine = [...new Set(this.chaine.split(" "))];
|
const arraychaine = [...new Set(this.chaine.split(" "))];
|
||||||
|
|
||||||
arraychaine.forEach(element => {
|
arraychaine.forEach(element => {
|
||||||
if (element != "") {
|
if (element != "") {
|
||||||
this.getchaine(element);
|
this.$store.dispatch('getchaine',{num:element});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
parsechaine() {
|
parsechaine() {
|
||||||
const path = process.env.ROOT_API + "/api/v1/chaine/";
|
|
||||||
axios
|
return putparsechaine()
|
||||||
.put(path)
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (res.data == "OK") {
|
if (res.data == "OK") {
|
||||||
alert("update database OK");
|
alert("update database OK");
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import App from './App';
|
import App from './App';
|
||||||
import router from './router';
|
import router from './router';
|
||||||
|
import store from './store'
|
||||||
import './../node_modules/bulma/css/bulma.css'
|
import './../node_modules/bulma/css/bulma.css'
|
||||||
Vue.config.productionTip = false;
|
Vue.config.productionTip = false;
|
||||||
|
|
||||||
@ -10,6 +11,7 @@ Vue.config.productionTip = false;
|
|||||||
new Vue({
|
new Vue({
|
||||||
el: '#app',
|
el: '#app',
|
||||||
router,
|
router,
|
||||||
|
store,
|
||||||
components: { App },
|
components: { App },
|
||||||
template: '<App/>',
|
template: '<App/>',
|
||||||
});
|
});
|
||||||
|
63
client/src/store/index.js
Normal file
63
client/src/store/index.js
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
// src/store/index.js
|
||||||
|
|
||||||
|
import Vue from 'vue'
|
||||||
|
import Vuex from 'vuex'
|
||||||
|
import { fetchchaine, fetchemission } from '../api';
|
||||||
|
Vue.use(Vuex)
|
||||||
|
const state = {
|
||||||
|
// single source of data
|
||||||
|
arrayresultchaines: [],
|
||||||
|
}
|
||||||
|
const API_PATH=`${process.env.ROOT_API}/api/v1`;
|
||||||
|
const actions = {
|
||||||
|
// asynchronous operations
|
||||||
|
getchaine(context,{num}) {
|
||||||
|
|
||||||
|
return fetchchaine(num)
|
||||||
|
.then( res => {
|
||||||
|
if (res.status === 200){
|
||||||
|
context.dispatch('getemission',{chaine:num,name:res.data})
|
||||||
|
}else{
|
||||||
|
context.commit('push_chaine',{chaine:num,name:res.data})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getemission(context,{chaine,name}){
|
||||||
|
return fetchemission (chaine)
|
||||||
|
.then(res_emission => {
|
||||||
|
context.commit('push_chaine',{chaine:chaine,name:name,emission:res_emission.data})
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const mutations = {
|
||||||
|
// isolated data mutations
|
||||||
|
push_chaine(state,payload){
|
||||||
|
if(!payload.name){
|
||||||
|
state.arrayresultchaines.push({ chaine: payload.chaine, name: "inconnue" });
|
||||||
|
}else{
|
||||||
|
state.arrayresultchaines.push({chaine: payload.chaine,name: payload.name,emission: payload.emission});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const getters = {
|
||||||
|
// reusable data accessors
|
||||||
|
}
|
||||||
|
|
||||||
|
const store = new Vuex.Store({
|
||||||
|
state,
|
||||||
|
actions,
|
||||||
|
mutations,
|
||||||
|
getters
|
||||||
|
})
|
||||||
|
|
||||||
|
export default store
|
Loading…
Reference in New Issue
Block a user