plein de chose api vdm marche affichage en cour

This commit is contained in:
antoine 2016-07-10 18:40:50 +02:00
parent 2fad435961
commit e4577bb90f
25 changed files with 440 additions and 0 deletions

1
.idea/.name Normal file
View File

@ -0,0 +1 @@
vdmAPI

14
.idea/misc.xml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.5.1 (/usr/bin/python3.5)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/vdmAPI.iml" filepath="$PROJECT_DIR$/.idea/vdmAPI.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

8
.idea/vdmAPI.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

202
.idea/workspace.xml Normal file
View File

@ -0,0 +1,202 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="6e7a9d99-3e6a-452b-9a27-b69955504578" name="Default" comment="" />
<ignored path="vdmAPI.iws" />
<ignored path=".idea/workspace.xml" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ChangesViewManager" flattened_view="true" show_ignored="false" />
<component name="CreatePatchCommitExecutor">
<option name="PATCH_PATH" value="" />
</component>
<component name="ExecutionTargetManager" SELECTED_TARGET="default_target" />
<component name="FavoritesManager">
<favorites_list name="vdmAPI" />
</component>
<component name="FileEditorManager">
<leaf>
<file leaf-file-name="main.py" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="8" column="0" selection-start-line="8" selection-start-column="0" selection-end-line="8" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Display.py" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/VDMAPI/Display.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.7576737">
<caret line="64" column="28" selection-start-line="64" selection-start-column="28" selection-end-line="64" selection-end-column="28" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/VDMAPI/Display.py" />
</list>
</option>
</component>
<component name="NamedScopeManager">
<order />
</component>
<component name="ProjectFrameBounds">
<option name="y" value="19" />
<option name="width" value="1366" />
<option name="height" value="730" />
</component>
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1">
<flattenPackages />
<showMembers />
<showModules />
<showLibraryContents />
<hideEmptyPackages />
<abbreviatePackageNames />
<autoscrollToSource />
<autoscrollFromSource />
<sortByType />
</navigator>
<panes>
<pane id="Scratches" />
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="vdmAPI" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="vdmAPI" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="vdmAPI" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="vdmAPI" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="vdmAPI" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="VDMAPI" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode" />
</PATH_ELEMENT>
</PATH>
</subPane>
</pane>
</panes>
</component>
<component name="PropertiesComponent">
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
</component>
<component name="ShelveChangesManager" show_recycled="false" />
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="6e7a9d99-3e6a-452b-9a27-b69955504578" name="Default" comment="" />
<created>1468084486688</created>
<option name="number" value="Default" />
<updated>1468084486688</updated>
</task>
<servers />
</component>
<component name="ToolWindowManager">
<frame x="0" y="19" width="1366" height="730" extended-state="6" />
<editor active="false" />
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.20204978" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
<window_info id="Application Servers" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Python Console" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="SLIDING" type="SLIDING" visible="false" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
</layout>
</component>
<component name="Vcs.Log.UiProperties">
<option name="RECENTLY_FILTERED_USER_GROUPS">
<collection />
</option>
<option name="RECENTLY_FILTERED_BRANCH_GROUPS">
<collection />
</option>
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager />
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/main.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.0">
<caret line="8" column="0" selection-start-line="8" selection-start-column="0" selection-end-line="8" selection-end-column="0" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/VDMAPI/Display.py">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="0.7576737">
<caret line="64" column="28" selection-start-line="64" selection-start-column="28" selection-end-line="64" selection-end-column="28" />
<folding>
<element signature="e#0#20#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component>
</project>

View File

@ -0,0 +1,7 @@
# import all module include into current package
__name__ = "VDMAPI"
__version__ = 1.0
__author__ = "antoine roux"
__author_email__= "antoinroux@hotmail.fr"
__url__ = "antoine-roux.tk"
__description__ = "an api for recover a list of random vdm from vdm.fr and display it on different GUI (i3, tkinter, windows or commande line"

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

12
VDMAPI/Display/console.py Normal file
View File

@ -0,0 +1,12 @@
from ..VDM import VDM
class console(object):
"""display all vdm into console"""
def __init__(self):
super(console, self).__init__()
self.v = VDM()
def render(self):
lstAllVDM = self.v.get()
for i, vdm in enumerate(lstAllVDM):
print(str(i)+" : "+vdm)

20
VDMAPI/Display/i3.py Normal file
View File

@ -0,0 +1,20 @@
from ..VDM import VDM
import subprocess
import i3
class i3(object):
"""display all vdm into i3 menu"""
def __init__(self):
super(i3, self).__init__()
self.v = VDM()
def render(self):
lstAllVDM = self.v.get()
dmenu = subprocess.Popen(['/usr/bin/dmenu', '-i','-l', str(len(lstAllVDM))],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
menu_str = '\n'.join(lstAllVDM)
win_str = dmenu.communicate(menu_str.encode('utf-8'))[0].decode('utf-8').rstrip()
print(win_str)

18
VDMAPI/Display/tkinter.py Normal file
View File

@ -0,0 +1,18 @@
from ..VDM import VDM
import tkinter as tk
import pygubu
import VDMAPI
import os
class tkinter:
def __init__(self):
self.root = tk.Tk()
builder = builder = pygubu.Builder()
uiPath = os.path.join(VDMAPI.__path__[0], './', 'tkinter.ui')
builder.add_from_file(uiPath)
mainwindow = builder.get_object('frame', self.root)
def render(self):
self.root.mainloop()

12
VDMAPI/Display/windows.py Normal file
View File

@ -0,0 +1,12 @@
from ..VDM import VDM
class windows(object):
"""display all vdm into windows os"""
def __init__(self):
super(windows, self).__init__()
v = VDM()
def render(self):
lstAllVDM = self.v.get()
for i, vdm in enumerate(lstAllVDM):
print(str(i)+" : "+vdm)

26
VDMAPI/HtmlParser.py Normal file
View File

@ -0,0 +1,26 @@
from html.parser import HTMLParser
from html.entities import name2codepoint
class MyHTMLParser(HTMLParser):
def __init__(self):
super(MyHTMLParser, self).__init__()
self.vdm = []
self.save = False
def _searchClass(self, listTuple, className="post article"):
for v in listTuple:
if v[0] == 'class' and v[1] == className:
return True
return False
def handle_starttag(self, tag, attrs):
if tag == "p" and self._searchClass(attrs, className="content"):
self.save = True
def handle_data(self, data):
if self.save:
self.vdm.append(data)
self.save = False
def getText(self):
return self.vdm

30
VDMAPI/VDM.py Normal file
View File

@ -0,0 +1,30 @@
from .HtmlParser import MyHTMLParser
import requests
class VDM(object):
"""VDM module for recover random VDM"""
def __init__(self):
self.url = "http://www.viedemerde.fr/aleatoire"
self.vdm = {}
def get(self):
try:
r = requests.get(self.url)
r.encoding = 'utf-8' # ISO-8859-1
if(r.status_code == requests.codes.ok):
parser = MyHTMLParser()
parser.feed(r.text)
self.vdm = parser.getText()
print("Sucess {}".format(r.status_code))
return self.vdm
else:
print("Error {}".format(r.status_code))
except ConnectionError as e:
print("Connection error {}".format(e))

0
VDMAPI/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

46
VDMAPI/tkinter.ui Normal file
View File

@ -0,0 +1,46 @@
<?xml version='1.0' encoding='utf-8'?>
<interface>
<object class="tk.Frame" id="frame">
<property name="height">200</property>
<property name="width">200</property>
<layout>
<property name="column">0</property>
<property name="propagate">True</property>
<property name="row">0</property>
</layout>
<child>
<object class="tk.Button" id="btn_prev">
<property name="height">3</property>
<property name="text" translatable="yes">&lt;&lt;</property>
<layout>
<property name="column">0</property>
<property name="propagate">True</property>
<property name="row">0</property>
<property name="sticky">w</property>
</layout>
</object>
</child>
<child>
<object class="tk.Button" id="btn_next">
<property name="height">3</property>
<property name="text" translatable="yes">&gt;&gt;</property>
<layout>
<property name="column">2</property>
<property name="propagate">True</property>
<property name="row">0</property>
<property name="sticky">e</property>
</layout>
</object>
</child>
<child>
<object class="tk.Message" id="lbl_vdm">
<property name="text" translatable="yes">No vdm pull for the moment</property>
<layout>
<property name="column">1</property>
<property name="propagate">True</property>
<property name="row">0</property>
</layout>
</object>
</child>
</object>
</interface>

30
main.py Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env python
import sys
if __name__ == "__main__":
from VDMAPI.Display.console import console as display
if "-d" in sys.argv:
index = next(i for i, c in enumerate(sys.argv) if c == "-d")
if len(sys.argv) > index+1:
displayType = sys.argv[index+1]
if displayType == "i3":
from VDMAPI.Display.i3 import i3 as display
elif displayType == "tkinter":
from VDMAPI.Display.tkinter import tkinter as display
elif displayType == "windows":
from VDMAPI.Display.windows import windows as display
elif displayType == "console":
None
else:
print("Error bad display mode accepted value are : i3, tkinter, windows of console")
else:
print("Error too few argument -d need value : i3, tkinter, windows of console")
d = display()
d.render()