arihantvyavhare commited on
Commit
1b4a8a1
1 Parent(s): 2557110

created .pynb to .py converter

Browse files
Files changed (3) hide show
  1. converter.py +25 -0
  2. tips.ipynb +4 -2
  3. tips.py +23 -0
converter.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ file = 'tips.ipynb'
4
+
5
+ code = json.load(open(file))
6
+ filename = file.split(".")[0]
7
+ py_file = open(f"{filename}.py", "w+")
8
+
9
+ for cell in code['cells']:
10
+ if cell['cell_type'] == 'code':
11
+ if "#| export" in cell['source'][0]:
12
+ for line in cell['source'][1:]:
13
+ py_file.write(line)
14
+
15
+ py_file.write("\n")
16
+ elif cell['cell_type'] == 'markdown':
17
+ py_file.write("\n")
18
+ for line in cell['source']:
19
+ if line and line[0] == "#":
20
+ py_file.write(line)
21
+ else:
22
+ py_file.write("#* " + line)
23
+ py_file.write("\n")
24
+
25
+ py_file.close()
tips.ipynb CHANGED
@@ -6,7 +6,9 @@
6
  "metadata": {},
7
  "source": [
8
  "# Tips:\n",
9
- "## downloading images using duckduckgo and fastbook"
 
 
10
  ]
11
  },
12
  {
@@ -58,7 +60,7 @@
58
  "urls = search_images_ddg(query, max_images = 5 )\n",
59
  "\n",
60
  "len(urls)\n",
61
- "#| export \n",
62
  "# for url in urls : print(url)"
63
  ]
64
  },
 
6
  "metadata": {},
7
  "source": [
8
  "# Tips:\n",
9
+ "## downloading images using duckduckgo and fastbook\n",
10
+ "\n",
11
+ "test"
12
  ]
13
  },
14
  {
 
60
  "urls = search_images_ddg(query, max_images = 5 )\n",
61
  "\n",
62
  "len(urls)\n",
63
+ "\n",
64
  "# for url in urls : print(url)"
65
  ]
66
  },
tips.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Tips:
3
+ ## downloading images using duckduckgo and fastbook
4
+ #*
5
+ #* test
6
+
7
+ from fastbook import *
8
+
9
+ query = "joker"
10
+
11
+ urls = search_images_ddg(query, max_images = 5 )
12
+
13
+ len(urls)
14
+
15
+ # for url in urls : print(url)
16
+ for i,url in enumerate(urls):
17
+ download_url(url,f"data/{query}/{query}_{i+1}.jpg")
18
+ import shutil
19
+
20
+ shutil.rmtree(f"data/{query}")
21
+
22
+
23
+