圖像提取器庫可協助使用者在任何日期和時間透過網路下載任何類型的圖像。這些圖像將作為作業下載,然後讓使用者知道圖像已下載。
很多時候,我們需要一堆圖像才能運作。我們可以考慮這樣的例子,例如在貓和狗圖像上訓練機器學習模型,或者只需單擊一下即可在我們的筆記型電腦上擁有數百張漂亮的桌面/行動壁紙。在這種情況下,我們立即需要數百張圖像。這個問題可以使用圖像提取器庫來解決。可實現以下用例:
$ pip install ImageExtractor
from flask import Flask
from flask_cors import cross_origin
from ImageExtractor . Extractor import ImageExtractor Class
import datetime
import threading
import time
import os
app = Flask ( __name__ )
class ThreadClass :
def __init__ ( self , req_id , time_to_sleep ,):
self . req_id = str ( req_id )
self . time_to_sleep = time_to_sleep
self . thread = threading . Thread ( target = self . sleep )
self . thread . start ()
def sleep ( self ):
try :
# Sleep for the given time
time . sleep ( self . time_to_sleep )
# Wait until the zip file is not ready
while not os . path . exists ( self . req_id + '_zipfile.zip' ):
print ( 'File not exists' )
time . sleep ( 5 )
print ( 'File exists now' )
time . sleep ( 30 )
# Deleting the file after 10 seconds
ImageExtractor Class . delete_file ( self . req_id )
print ( 'Files are deleted' )
except Exception as e :
print ( e )
# Home page route
@ app . route ( '/' , methods = [ 'GET' ])
@ cross_origin ()
def index ():
try :
# Creating the object of ImageExtractor Class
image_extractor = ImageExtractor Class ()
# Current datetime
current = datetime . datetime . now ()
# The scheduled datetime
date_inserted = current + datetime . timedelta ( minutes = 5 )
date_str = str ( date_inserted . year ) + '-' + str ( date_inserted . month ) + '-' + str ( date_inserted . day )
time_str = str ( date_inserted . hour ) + ':' + str ( date_inserted . minute )
req_id , time_to_sleep = image_extractor . schedule_job ( 'some_sample_query' , date_str , time_str , 54 )
# Time to sleep the thread
time_to_sleep = current + datetime . timedelta ( seconds = time_to_sleep )
total_seconds_sleep = time_to_sleep - datetime . datetime . now ()
# Total seconds to sleep the thread
total_seconds_sleep = int ( total_seconds_sleep . total_seconds ())
ThreadClass ( req_id , total_seconds_sleep )
return '<h1> req id is ' + str ( req_id ) + ' and time_to_sleep is ' + str ( total_seconds_sleep ) + ' seconds</h1>'
except Exception as e :
return "<h1> Error is " + str ( e ) + "</h1>"
if __name__ == '__main__' :
app . debug = True
app . run ()
您已經準備好出發了!此時,在給定的日期和時間,圖像將開始下載。
想做出貢獻嗎?偉大的!
若要修復錯誤或增強現有模組,請執行下列步驟:
git checkout -b new-feature
git commit -am " New feature added "
git push origin new-feature
如果您發現任何錯誤或對可以實現的新功能有一些想法,您可以在此處提出問題,也可以直接向我們發送電子郵件:[email protected]。
請包含範例查詢及其對應的結果。
客戶:
伺服器:
如果您有任何回饋,請透過 [email protected] 聯絡我們
答 - 不。任務結束後,將在用戶端建立 zip 檔案。
Ans - 一次最多可以下載 2000 張圖片。如果需要更多,我們可以簡單地再次提交查詢。
進階設計文檔
低階設計文檔
線框
建築學
麻省理工學院許可證
版權所有 (c) [2021] [Shreyas Parab]
特此免費授予任何獲得本軟體及相關文件文件(「軟體」)副本的人不受限制地使用本軟體,包括但不限於使用、複製、修改、合併的權利、發布、散佈、再授權和/或銷售軟體的副本,並允許向其提供軟體的人員這樣做,但須滿足以下條件:
上述版權聲明和本授權聲明應包含在本軟體的所有副本或主要部分中。
本軟體以「現況」提供,不提供任何明示或暗示的保證,包括但不限於適銷性、特定用途的適用性和不侵權的保證。 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軟體.