/
wcmnikolatags.py
181 lines (100 loc) · 2.48 KB
/
wcmnikolatags.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# coding: utf-8
# wcm Nikola Tags
#
# convert ipynb/py doc imports as tags for nikola blog .meta files.
#
# When user searches for notebook to blog with bbknikola python script also get the tags for the .meta file. Open up the .py file and convert this:
#
# blogpost.py
#
# import requests
# import os
# import re
#
# Into:
#
# blogpost.meta
#
# blogpost
# blogpost
# 2015/02/31 00:00:00
# requests, os, re
# Categorie can be the name of the repo.
# Need a repo for Nikola scripts
# In[26]:
import modulefinder
import runpy
import os
from walkdir import filtered_walk, dir_paths, all_paths, file_paths
# In[22]:
mwcm = modulefinder.ModuleFinder()
# In[23]:
mwcm.any_missing()
# In[24]:
mwcm.run_script('/home/wcmckee/github/niketa/rgdsnatch.py')
# In[35]:
mwcm.path
# In[39]:
mwcm.scan_code
# In[10]:
from splinter import Browser
browser = Browser()
# In[11]:
browser.visit('http://google.com')
# In[12]:
browser.title
# In[9]:
browser.request_url
# In[15]:
#browser.click_link_by_href('http://www.google.co.nz/preferences')
# In[1]:
import time
# In[19]:
#Code for open up web browser on library system and
#acceot their t&c.
#Need to get web address to go to, and button find_by_name
#to click.
from splinter import Browser
with Browser() as browser:
# Visit URL
url = "http://www.google.com"
browser.visit(url)
browser.fill('q', 'artcontrol')
# Find and click the 'search' button
button = browser.find_by_name('btnG')
# Interact with elements
button.click()
time.sleep(5)
if browser.is_text_present('artcontrol.me'):
print "Yes, the official website was found!"
else:
print "No, it wasn't found... We need to improve our SEO techniques"
# In[ ]:
# In[27]:
mwcm.report()
# In[28]:
runpy.run_module('requests')
# In[ ]:
# In[29]:
nbog = raw_input('Name of notebook to tag: ')
# In[30]:
files = file_paths(filtered_walk('/home/wcmckee/github/', depth=100, included_files=[nbog + '.ipynb']))
# In[35]:
#Easier to access ipynb and access the code import cell.
#Parse the notebook for import tags
#IPython module wrapper for returning list of imported modules
#from a ipynb file.
#Get the list of modules for tags from this.
# In[32]:
for fil in files:
#print fil
opfil = open(fil, 'r')
print opfil.read()
opfil.close()
# In[33]:
opfilz = open(fil, 'r')
opfilz.read()
# In[34]:
#python module that can be used to scan .py files and return
#the imports as a list.
# In[ ]: